aries-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christian Schneider <ch...@die-schneider.net>
Subject Re: Aries JPA with JTA Transactions
Date Sat, 28 Apr 2012 18:33:14 GMT
I think there are two problems here. First you should either use a 
XADataSource or set non-jta-datasource in persistence.xml.
The second is that I am not sure this works with Hibernate. I got it 
working with OpenJPA.

You can take a look at my tutorial too and the github project:
http://www.liquid-reality.de/x/LYBk

There you find a complete project ready to run in Karaf.

Christian

Am 28.04.2012 01:20, schrieb Diane Andrus:
> Hi,
> I'm trying to get a JTA transaction working in Karaf on a very simple
> model.  I was saving&  retrieving the model via my hibernate mapping
> at some point, but now I am not.
> I started with this tutorial (which seems very good in getting the
> concept of jpa&  osgi)
> http://jaxenter.com/tutorial-using-jpa-in-an-osgi-environment-36661.html,
> but, it doesn't use a DataSource and JTA transactions, and make Aries
> manage my transactions.  I didn't think it would be so hard.
>
> Most of this is pretty verbatim from the Aries JPA home page.
>
> There's this cryptic remark, that I'm not quite sure what it means....
>          "To access to the datasource, you must provide within the or
> depending if you use a JTA transaction manager or not.
>
>          <persistence-unit name="ReportIncident" transaction-type="JTA">
>          <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
>
>          <jta-data-source>osgi:service/javax.sql.DataSource/(osgi.jndi.service.name=jdbc/reportincidentdb)</jta-data-source>"
>
> Is there a JTA transaction manager bundle that I have to deploy as
> well?  I'm using karaf, and I just installed the jpa, jndi,&
> transaction features.  I have some commons bundles&  the derby driver
> and I believe all of the dependencies that I need running....but I am
> missing some secret sauce here. I'm using hibernate as my JPA provider
> (which is probably the problem....some missing library or crazy
> classloading issue)
>
> My current error:
> 2012-04-27 18:30:10,518 | INFO  | FelixStartLevel  |
> ConnectionProviderFactory        | ection.ConnectionProviderFactory
> 173 | 65 - hibernate-wrapper - 1.0.0.SNAPSHOT | Initializing
> connection provider:
> org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider
> 2012-04-27 18:30:10,522 | INFO  | FelixStartLevel  |
> ctedDataSourceConnectionProvider | ctedDataSourceConnectionProvider
> 62 | 65 - hibernate-wrapper - 1.0.0.SNAPSHOT | Using provided
> datasource
>
> 2012-04-27 18:30:10,534 | DEBUG | lixDispatchQueue | container
>               | ?                                   ? | 53 -
> org.apache.aries.jpa.container - 0.3.0 | FrameworkEvent ERROR
> java.lang.IllegalStateException: The bundle
> com.mycompany.PersistenceModel_1.0.0.SNAPSHOT is not started.
>        at org.apache.aries.jpa.container.unit.impl.DelayedLookupDataSource.getDs(DelayedLookupDataSource.java:50)[53:org.apache.aries.jpa.container:0.3.0]
>        at org.apache.aries.jpa.container.unit.impl.DelayedLookupDataSource.getConnection(DelayedLookupDataSource.java:74)[53:org.apache.aries.jpa.container:0.3.0]
>        at org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider.getConnection(InjectedDataSourceConnectionProvider.java:71)[65:gov.navair.dep.hibernate-wrapper:1.0.0.SNAPSHOT]
>        at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:113)[65:gov.navair.dep.hibernate-wrapper:1.0.0.SNAPSHOT]
>        at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2836)[65:gov.navair.dep.hibernate-wrapper:1.0.0.SNAPSHOT]
>        at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2832)[65:gov.navair.dep.hibernate-wrapper:1.0.0.SNAPSHOT]
>        at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1843)[65:gov.navair.dep.hibernate-wrapper:1.0.0.SNAPSHOT]
>        at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:906)[65:gov.navair.dep.hibernate-wrapper:1.0.0.SNAPSHOT]
>        at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:74)[65:gov.navair.dep.hibernate-wrapper:1.0.0.SNAPSHOT]
>        at org.apache.aries.jpa.container.impl.EntityManagerFactoryManager.createEntityManagerFactories(EntityManagerFactoryManager.java:263)[53:org.apache.aries.jpa.container:0.3.0]
>        at org.apache.aries.jpa.container.impl.EntityManagerFactoryManager.bundleStateChange(EntityManagerFactoryManager.java:153)[53:org.apache.aries.jpa.container:0.3.0]
>        at org.apache.aries.jpa.container.impl.PersistenceBundleManager.modifiedBundle(PersistenceBundleManager.java:283)[53:org.apache.aries.jpa.container:0.3.0]
>        at org.osgi.util.tracker.BundleTracker$Tracked.customizerModified(BundleTracker.java:453)[karaf.jar:2.2.5]
>        at org.osgi.util.tracker.AbstractTracked.track(AbstractTracked.java:237)[karaf.jar:2.2.5]
>        at org.osgi.util.tracker.BundleTracker$Tracked.bundleChanged(BundleTracker.java:413)[karaf.jar:2.2.5]
>        at org.apache.felix.framework.util.EventDispatcher.invokeBundleListenerCallback(EventDispatcher.java:807)[org.apache.felix.framework-3.0.9.jar:]
>        at org.apache.felix.framework.util.EventDispatcher.fireEventImmediately(EventDispatcher.java:729)[org.apache.felix.framework-3.0.9.jar:]
>        at org.apache.felix.framework.util.EventDispatcher.fireBundleEvent(EventDispatcher.java:610)[org.apache.felix.framework-3.0.9.jar:]
>        at org.apache.felix.framework.Felix.fireBundleEvent(Felix.java:3761)[org.apache.felix.framework-3.0.9.jar:]
>        at org.apache.felix.framework.Felix.access$600(Felix.java:80)[org.apache.felix.framework-3.0.9.jar:]
>        at org.apache.felix.framework.Felix$FelixResolver.fireResolvedEvents(Felix.java:4299)[org.apache.felix.framework-3.0.9.jar:]
>        at org.apache.felix.framework.Felix$FelixResolver.resolve(Felix.java:4065)[org.apache.felix.framework-3.0.9.jar:]
>        at org.apache.felix.framework.Felix.resolveBundle(Felix.java:3439)[org.apache.felix.framework-3.0.9.jar:]
>        at org.apache.felix.framework.Felix.startBundle(Felix.java:1734)[org.apache.felix.framework-3.0.9.jar:]
>        at org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:1163)[org.apache.felix.framework-3.0.9.jar:]
>        at org.apache.felix.framework.StartLevelImpl.run(StartLevelImpl.java:264)[org.apache.felix.framework-3.0.9.jar:]
>
>
>
> And it's crazy weird, because then my model bundle status is ACTIVE,
> even though it failed to really start.
> So, of course, my service won't start, b/c model bundle never finished
> it's JPA stuff and it never got Aries to export an Entity Manager
> Factory for it....
> I've actually lost track of everything I've tried.  I started out with
> wanting to have a clean model bundle, not dependent on jaxb or jpa
> stuff, but, that didn't seem to work.  So, I'm at the point where I
> just want a JTA transaction working with Aries taking care of
> transactions for me.  That would be my goal for now.  I hope its some
> simple thing I missed.  Any help would be appreciated...Please
>
> Thanks,
>
> Diane
>
> ==========
> Bundle #1:  Datasource
> I pretty much copied by datasource config from the main page of Aries JPA.
> <!-- DataSource Derby -->
>    <bean id="dataSourceDerby"
> class="org.apache.commons.dbcp.BasicDataSource"
> destroy-method="close">
>        <property name="driverClassName"
> value="org.apache.derby.jdbc.EmbeddedDriver" />
>        <property name="url" value="jdbc:derby:memory:pu_apps;create=true" />
>        <property name="username" value="" />
>        <property name="password" value="" />
>    </bean>
>
>    <!-- Expose DataSource as JNDI reference -->
>    <service ref="dataSourceDerby" interface="javax.sql.DataSource">
>        <service-properties>
>            <entry key="osgi.jndi.service.name" value="jdbc/derbyds"/>
>        </service-properties>
>    </service>
>
> ==========
> Bundle #2:  Persistence Model
> java class: com/mycompany/persistencemodel/App - simple POJO
> public class App {
>
>    private Integer appId;
>    private String name;
>    private String status;
>    private String version;
>    private String description;
>
> ....default constructor&  generated getter&  setter for each property....
> }
>
> META-INF/persistence.xml
>   <persistence-unit name="pu_apps" transaction-type="JTA">
>        <provider>org.hibernate.ejb.HibernatePersistence</provider>
>        <jta-data-source>osgi:service/javax.sql.DataSource/(osgi.jndi.service.name=jdbc/derbyds)</jta-data-source>
>        <mapping-file>mappings/app.hbm.xml</mapping-file>
>
>        <properties>
>            <property name="javax.persistence.jdbc.driver"
> value="org.apache.derby.jdbc.EmbeddedDriver"/>
>        <!-- for hibernate -->
>            <property name="hibernate.dialect"
> value="org.hibernate.dialect.DerbyDialect"/>
>            <property name="hibernate.hbm2ddl.auto" value="create"/>
>            <property name="hibernate.show_sql" value="true"/>
>
>        </properties>
>    </persistence-unit>
> (and yes...<Meta-Persistence>META-INF/persistence.xml</Meta-Persistence>
> in my pom.xml)
>
> mappings/app.hbm.xml
> <hibernate-mapping>
>    <class name="com.mycompany.persistencemodel.App" table="APP">
>        <id column="APP_ID" name="appId">
>             <generator class="identity">
>             </generator>
>        </id>
>        <property column="NAME" name="name"/>
>        <property column="STATUS" name="status"/>
>        <property column="VERSION" name="version"/>
>        <property column="DESCRIPTION" name="description"/>
>    </class>
> </hibernate-mapping>
>
> ==========
> Bundle #3
> hibernate wrapper from
> http://jaxenter.com/tutorial-using-jpa-in-an-osgi-environment-36661.html
>
> ==========
> Bundle #4
> Persistence Service
> <bean id="defaultPersistenceService"
>      class="com.mycompany.service.impl.DefaultPersistenceService">
>        <tx:transaction method="*" value="Required" />
>        <property name="bc" ref="blueprintBundleContext"/>
>        <jpa:context property="entityManager" unitname="pu_apps" />
>    </bean>
>
>    <service
>    id="persistenceService"
>    interface="com.mycompany.service.PersistenceService"
>    ref="defaultPersistenceService">
>    </service>


-- 

Christian Schneider
http://www.liquid-reality.de

Open Source Architect
Talend Application Integration Division http://www.talend.com


Mime
View raw message