You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@karaf.apache.org by dealbitte <an...@gmail.com> on 2012/10/26 12:48:40 UTC

JPA Usage: Strategy for using Hibernate + Postgresql

Hi

I am trying to set up Hibernate and Postgresql in conjunction with Karaf. I
have a maven project (archetype: osgi)  that depends on Hibernate and
Postgresql and I want to install this project in karaf. I would like to know
if there are design patterns to set up a JPA provider (like Hibernate) along
with a database (like Postgres). 

I installed hibernate dependencies, via feature file shown below

  <feature name="hibernate">
	<bundle>wrap:mvn:org.hibernate/hibernate-core/4.1.7.Final</bundle>
       
<bundle>wrap:mvn:org.hibernate/hibernate-entitymanager/4.1.7.Final</bundle>

<bundle>wrap:mvn:org.hibernate.javax.persistence/hibernate-jpa-2.0-api/1.0.1.Final</bundle>

<bundle>wrap:mvn:org.hibernate.common/hibernate-commons-annotations/4.0.1.Final</bundle>
	<bundle>wrap:mvn:org.jboss.logging/jboss-logging/3.1.0.GA</bundle>
  </feature>

When I tried to install my bundle, it complains about missing
'hibernate.cfg.xml' even though this is available inside the bundle. 

I am looking for some examples, tutorials that can help to understand the
usage of JPA provider with database. I am not restricted to Hibernate and
Postgres. 

regards,
Rakesh



--
View this message in context: http://karaf.922171.n3.nabble.com/JPA-Usage-Strategy-for-using-Hibernate-Postgresql-tp4026586.html
Sent from the Karaf - User mailing list archive at Nabble.com.

Re: JPA Usage: Strategy for using Hibernate + Postgresql

Posted by James Carman <ja...@carmanconsulting.com>.
Yeah, that's a bit of a gotcha.  That should be highlighted a bit more.

On Mon, Oct 29, 2012 at 9:13 AM, dealbitte <an...@gmail.com> wrote:
> Solved the problem. I made a configuration error in maven .pom file
>
> added the line
> <Meta-Persistence>META-INF/persistence.xml</Meta-Persistence>
> to maven-bundle-plugin
>
> regards.
>
>
>
> --
> View this message in context: http://karaf.922171.n3.nabble.com/JPA-Usage-Strategy-for-using-Hibernate-Postgresql-tp4026586p4026602.html
> Sent from the Karaf - User mailing list archive at Nabble.com.

Re: JPA Usage: Strategy for using Hibernate + Postgresql

Posted by dealbitte <an...@gmail.com>.
Solved the problem. I made a configuration error in maven .pom file

added the line
<Meta-Persistence>META-INF/persistence.xml</Meta-Persistence>
to maven-bundle-plugin

regards.



--
View this message in context: http://karaf.922171.n3.nabble.com/JPA-Usage-Strategy-for-using-Hibernate-Postgresql-tp4026586p4026602.html
Sent from the Karaf - User mailing list archive at Nabble.com.

Re: JPA Usage: Strategy for using Hibernate + Postgresql

Posted by dealbitte <an...@gmail.com>.
I started to work with openJPA and created a osgi bundle (simpleProject)
based on this example,
http://www.liquid-reality.de/display/liquid/2012/01/13/Apache+Karaf+Tutorial+Part+6+-+Database+Access

In karaf 2.3.0, I installed the following features & bundles:

features:install jndi jpa transaction
install -s mvn:org.apache.derby/derby/10.8.2.2
install -s mvn:commons-collections/commons-collections/3.2.1
install -s mvn:commons-pool/commons-pool/1.5.4
install -s mvn:commons-dbcp/commons-dbcp/1.4
install -s mvn:commons-lang/commons-lang/2.6
install -s wrap:mvn:net.sourceforge.serp/serp/1.13.1
install -s mvn:org.apache.openjpa/openjpa/2.1.1
install -s mvn:org.apache.aries/org.apache.aries.util/0.4

Then I dropped the following datasource-derby.xml (taken from
www.liquid-reality.de example above)

<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                default-activation="eager">  
    <bean id="dataSource"
class="org.apache.derby.jdbc.EmbeddedXADataSource">
       <property name="databaseName" value="test"/>
       <property name="createDatabase" value="create" />
    </bean>
  
    <service ref="dataSource" interface="javax.sql.DataSource">
        <service-properties>
            <entry key="osgi.jndi.service.name" value="jdbc/derbyds"/>
        </service-properties>
    </service>

    <service ref="dataSource" interface="javax.sql.XADataSource">
        <service-properties>
            <entry key="osgi.jndi.service.name" value="jdbc/derbydsxa"/>
        </service-properties>
    </service>
  
</blueprint>

And once I install my OSGi bundle (simpleProject), the bundle blueprint
status remains in 'GracePeriod' and ultimately fails as shown below:

karaf@root> list
START LEVEL 100 , List Threshold: 50
   ID   State         Blueprint      Level  Name
[  67] [Active     ] [            ] [   80] Apache Derby 10.8
(10.8.2000002.1181258)
[  68] [Active     ] [            ] [   80] Commons Collections (3.2.1)
[  69] [Active     ] [            ] [   80] Commons Pool (1.5.4)
[  70] [Active     ] [            ] [   80] Commons DBCP (1.4)
[  71] [Active     ] [            ] [   80] Commons Lang (2.6)
[  72] [Active     ] [            ] [   80]
wrap_mvn_net.sourceforge.serp_serp_1.13.1 (0)
[  73] [Active     ] [            ] [   80] OpenJPA Aggregate Jar (2.1.1)
[  74] [Active     ] [            ] [   80] Apache Aries Util (0.4.0)
[  75] [Active     ] [Failure     ] [   80] openjpa.examplejpa OSGi Bundle
(0.1.0)
[  76] [Active     ] [Created     ] [   80] datasource-derby.xml (0.0.0)

>From log:
2012-10-29 12:30:05,506 | INFO  | rint Extender: 3 | BlueprintContainerImpl          
| container.BlueprintContainerImpl  330 | 7 -
org.apache.aries.blueprint.core - 1.0.1 | Bundle
my.own.examples.openjpa.examplejpa is waiting for dependencies
[(&(&(org.apache.aries.jpa.proxy.factory=true)(osgi.unit.name=person))(objectClass=javax.persistence.EntityManagerFactory))]

It is not clear what is missing here because
"javax.persistence.EntityManagerFactory" is part of feature:jpa
installation. Please guide me here.









--
View this message in context: http://karaf.922171.n3.nabble.com/JPA-Usage-Strategy-for-using-Hibernate-Postgresql-tp4026586p4026601.html
Sent from the Karaf - User mailing list archive at Nabble.com.

Re: JPA Usage: Strategy for using Hibernate + Postgresql

Posted by Johan Edstrom <se...@gmail.com>.
I'll third that.
Very easy to setup, quite a bit faster thanks to much less reflection.


On Oct 26, 2012, at 5:17 AM, Achim Nierbeck <bc...@googlemail.com> wrote:

> I just can second that, I have no hassle in using JPA with Aries
> blueprint, jpa and OpenJPA in my projects ...
> 
> regards, Achim
> 
> 2012/10/26 James Carman <ja...@carmanconsulting.com>:
>> OpenJPA is much more OSGi-friendly.  You might give that a go.  We've
>> switched and never looked back.
>> 
>> On Fri, Oct 26, 2012 at 6:48 AM, dealbitte <an...@gmail.com> wrote:
>>> Hi
>>> 
>>> I am trying to set up Hibernate and Postgresql in conjunction with Karaf. I
>>> have a maven project (archetype: osgi)  that depends on Hibernate and
>>> Postgresql and I want to install this project in karaf. I would like to know
>>> if there are design patterns to set up a JPA provider (like Hibernate) along
>>> with a database (like Postgres).
>>> 
>>> I installed hibernate dependencies, via feature file shown below
>>> 
>>>  <feature name="hibernate">
>>>        <bundle>wrap:mvn:org.hibernate/hibernate-core/4.1.7.Final</bundle>
>>> 
>>> <bundle>wrap:mvn:org.hibernate/hibernate-entitymanager/4.1.7.Final</bundle>
>>> 
>>> <bundle>wrap:mvn:org.hibernate.javax.persistence/hibernate-jpa-2.0-api/1.0.1.Final</bundle>
>>> 
>>> <bundle>wrap:mvn:org.hibernate.common/hibernate-commons-annotations/4.0.1.Final</bundle>
>>>        <bundle>wrap:mvn:org.jboss.logging/jboss-logging/3.1.0.GA</bundle>
>>>  </feature>
>>> 
>>> When I tried to install my bundle, it complains about missing
>>> 'hibernate.cfg.xml' even though this is available inside the bundle.
>>> 
>>> I am looking for some examples, tutorials that can help to understand the
>>> usage of JPA provider with database. I am not restricted to Hibernate and
>>> Postgres.
>>> 
>>> regards,
>>> Rakesh
>>> 
>>> 
>>> 
>>> --
>>> View this message in context: http://karaf.922171.n3.nabble.com/JPA-Usage-Strategy-for-using-Hibernate-Postgresql-tp4026586.html
>>> Sent from the Karaf - User mailing list archive at Nabble.com.
> 
> 
> 
> -- 
> 
> Apache Karaf <http://karaf.apache.org/> Committer & PMC
> OPS4J Pax Web <http://wiki.ops4j.org/display/paxweb/Pax+Web/>
> Committer & Project Lead
> OPS4J Pax for Vaadin
> <http://team.ops4j.org/wiki/display/PAXVAADIN/Home> Commiter & Project
> Lead
> blog <http://notizblog.nierbeck.de/>


Re: JPA Usage: Strategy for using Hibernate + Postgresql

Posted by Achim Nierbeck <bc...@googlemail.com>.
I just can second that, I have no hassle in using JPA with Aries
blueprint, jpa and OpenJPA in my projects ...

regards, Achim

2012/10/26 James Carman <ja...@carmanconsulting.com>:
> OpenJPA is much more OSGi-friendly.  You might give that a go.  We've
> switched and never looked back.
>
> On Fri, Oct 26, 2012 at 6:48 AM, dealbitte <an...@gmail.com> wrote:
>> Hi
>>
>> I am trying to set up Hibernate and Postgresql in conjunction with Karaf. I
>> have a maven project (archetype: osgi)  that depends on Hibernate and
>> Postgresql and I want to install this project in karaf. I would like to know
>> if there are design patterns to set up a JPA provider (like Hibernate) along
>> with a database (like Postgres).
>>
>> I installed hibernate dependencies, via feature file shown below
>>
>>   <feature name="hibernate">
>>         <bundle>wrap:mvn:org.hibernate/hibernate-core/4.1.7.Final</bundle>
>>
>> <bundle>wrap:mvn:org.hibernate/hibernate-entitymanager/4.1.7.Final</bundle>
>>
>> <bundle>wrap:mvn:org.hibernate.javax.persistence/hibernate-jpa-2.0-api/1.0.1.Final</bundle>
>>
>> <bundle>wrap:mvn:org.hibernate.common/hibernate-commons-annotations/4.0.1.Final</bundle>
>>         <bundle>wrap:mvn:org.jboss.logging/jboss-logging/3.1.0.GA</bundle>
>>   </feature>
>>
>> When I tried to install my bundle, it complains about missing
>> 'hibernate.cfg.xml' even though this is available inside the bundle.
>>
>> I am looking for some examples, tutorials that can help to understand the
>> usage of JPA provider with database. I am not restricted to Hibernate and
>> Postgres.
>>
>> regards,
>> Rakesh
>>
>>
>>
>> --
>> View this message in context: http://karaf.922171.n3.nabble.com/JPA-Usage-Strategy-for-using-Hibernate-Postgresql-tp4026586.html
>> Sent from the Karaf - User mailing list archive at Nabble.com.



-- 

Apache Karaf <http://karaf.apache.org/> Committer & PMC
OPS4J Pax Web <http://wiki.ops4j.org/display/paxweb/Pax+Web/>
Committer & Project Lead
OPS4J Pax for Vaadin
<http://team.ops4j.org/wiki/display/PAXVAADIN/Home> Commiter & Project
Lead
blog <http://notizblog.nierbeck.de/>

Re: JPA Usage: Strategy for using Hibernate + Postgresql

Posted by James Carman <ja...@carmanconsulting.com>.
OpenJPA is much more OSGi-friendly.  You might give that a go.  We've
switched and never looked back.

On Fri, Oct 26, 2012 at 6:48 AM, dealbitte <an...@gmail.com> wrote:
> Hi
>
> I am trying to set up Hibernate and Postgresql in conjunction with Karaf. I
> have a maven project (archetype: osgi)  that depends on Hibernate and
> Postgresql and I want to install this project in karaf. I would like to know
> if there are design patterns to set up a JPA provider (like Hibernate) along
> with a database (like Postgres).
>
> I installed hibernate dependencies, via feature file shown below
>
>   <feature name="hibernate">
>         <bundle>wrap:mvn:org.hibernate/hibernate-core/4.1.7.Final</bundle>
>
> <bundle>wrap:mvn:org.hibernate/hibernate-entitymanager/4.1.7.Final</bundle>
>
> <bundle>wrap:mvn:org.hibernate.javax.persistence/hibernate-jpa-2.0-api/1.0.1.Final</bundle>
>
> <bundle>wrap:mvn:org.hibernate.common/hibernate-commons-annotations/4.0.1.Final</bundle>
>         <bundle>wrap:mvn:org.jboss.logging/jboss-logging/3.1.0.GA</bundle>
>   </feature>
>
> When I tried to install my bundle, it complains about missing
> 'hibernate.cfg.xml' even though this is available inside the bundle.
>
> I am looking for some examples, tutorials that can help to understand the
> usage of JPA provider with database. I am not restricted to Hibernate and
> Postgres.
>
> regards,
> Rakesh
>
>
>
> --
> View this message in context: http://karaf.922171.n3.nabble.com/JPA-Usage-Strategy-for-using-Hibernate-Postgresql-tp4026586.html
> Sent from the Karaf - User mailing list archive at Nabble.com.