Quantcast

OpenJPA transactions

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

OpenJPA transactions

javidelgadillo
I've been banging my head against a wall for well over a week trying to get this to work.  So now I'm coming to the experts for help.

I've got Karaf 2.2.5, OpenJPA 2.2.0, and Aries 0.3 installed.  I've got an entity configured  via the persistence.xml.  The DataSources are loaded and a connection to the DB is acquired.  But when I call em.getTransaction().begin() the whole hing blows up.  It seems I'm winding up with the default JTAEntityManager that doesn't support Transacations, but attempts to set the TransactionManager via the properties section in the persistence.xml file aren't working.

Any ideas on what I'm doing wrong?

 My persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
        version="1.0">

        <persistence-unit name="metadataPersistenceUnit"
                transaction-type="JTA">
                <description>Persistence unit for Metadata</description>

                <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>

                <jta-data-source>osgi:service/javax.sql.XADataSource/(osgi.jndi.service.name=jdbc/jta)</jta-data-source>
                <non-jta-data-source>osgi:service/javax.sql.DataSource/(osgi.jndi.service.name=jdbc/nojta)</non-jta-data-source>

                <class>MetadataEntity</class>
                <exclude-unlisted-classes>true</exclude-unlisted-classes>
                <properties>
                        <property name="openjpa.Log" value="DefaultLevel=TRACE" />
                        <property name="openjpa.RuntimeUnenhancedClasses" value="unsupported" />
                        <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema" />
                        <property name="openjpa.TransactionMode" value="managed"/>
                        <property name="openjpa.ManagedRuntime" value="jndi(TransactionManagerName=osgi:service/javax.transaction.TransactionManager)"/>
                </properties>
               
        </persistence-unit>
</persistence>

Here's the stack trace I get when trying to persist an Entity to the DB:
Caused by: java.lang.IllegalStateException: Transaction management is not available for container managed EntityManagers
        at org.apache.aries.jpa.container.context.transaction.impl.JTAEntityManager.getTransaction(JTAEntityManager.java:244)
        at xxx.xxx.xxx.xxx(MetadataDAOImpl.java:65)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)[:1.6.0_17]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)[:1.6.0_17]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)[:1.6.0_17]
        at java.lang.reflect.Method.invoke(Method.java:597)[:1.6.0_17]
        at org.apache.aries.proxy.impl.ProxyHandler$1.invoke(ProxyHandler.java:50)
        at org.apache.aries.blueprint.proxy.Collaborator.invoke(Collaborator.java:91)
        at org.apache.aries.proxy.impl.ProxyHandler.invoke(ProxyHandler.java:78)
        at xxx.xxx.xxx(Unknown Source)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)[:1.6.0_17]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)[:1.6.0_17]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)[:1.6.0_17]
        at java.lang.reflect.Method.invoke(Method.java:597)[:1.6.0_17]
        at org.apache.aries.proxy.impl.ProxyHandler$1.invoke(ProxyHandler.java:50)
        at org.apache.aries.proxy.impl.DefaultWrapper.invoke(DefaultWrapper.java:31)
        at org.apache.aries.proxy.impl.ProxyHandler.invoke(ProxyHandler.java:78)
        at $Proxy33.saveNewMetadatas(Unknown Source)


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

AW: OpenJPA transactions

Boblitz John
 

> -----Ursprüngliche Nachricht-----
> Von: javidelgadillo [mailto:[hidden email]]
> Gesendet: Mittwoch, 28. März 2012 02:57
> An: [hidden email]
> Betreff: OpenJPA transactions
>
> I've been banging my head against a wall for well over a week
> trying to get this to work.  So now I'm coming to the experts
> for help.
>
> I've got Karaf 2.2.5, OpenJPA 2.2.0, and Aries 0.3 installed.
>  I've got an entity configured  via the persistence.xml.  The
> DataSources are loaded and a connection to the DB is
> acquired.  But when I call
> em.getTransaction().begin() the whole hing blows up.  It
> seems I'm winding up with the default JTAEntityManager that
> doesn't support Transacations, but attempts to set the
> TransactionManager via the properties section in the
> persistence.xml file aren't working.
>
> Any ideas on what I'm doing wrong?
>
>  My persistence.xml:
> <?xml version="1.0" encoding="UTF-8"?>
> <persistence xmlns="http://java.sun.com/xml/ns/persistence"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
> http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
> version="1.0">
>
> <persistence-unit name="metadataPersistenceUnit"
> transaction-type="JTA">
> <description>Persistence unit for Metadata</description>
>
>
> <provider>org.apache.openjpa.persistence.PersistenceProviderIm
> pl</provider>
>
>
> <jta-data-source>osgi:service/javax.sql.XADataSource/(osgi.jnd
> i.service.name=jdbc/jta)</jta-data-source>
>
> <non-jta-data-source>osgi:service/javax.sql.DataSource/(osgi.j
> ndi.service.name=jdbc/nojta)</non-jta-data-source>
>
> <class>MetadataEntity</class>
>
> <exclude-unlisted-classes>true</exclude-unlisted-classes>
> <properties>
> <property name="openjpa.Log"
> value="DefaultLevel=TRACE" />
> <property
> name="openjpa.RuntimeUnenhancedClasses" value="unsupported" />
> <property
> name="openjpa.jdbc.SynchronizeMappings" value="buildSchema" />
> <property
> name="openjpa.TransactionMode" value="managed"/>
> <property name="openjpa.ManagedRuntime"
> value="jndi(TransactionManagerName=osgi:service/javax.transact
> ion.TransactionManager)"/>
> </properties>
>
> </persistence-unit>
> </persistence>
>
> Here's the stack trace I get when trying to persist an Entity
> to the DB:
> Caused by: java.lang.IllegalStateException: Transaction
> management is not available for container managed EntityManagers
>         at
> org.apache.aries.jpa.container.context.transaction.impl.JTAEnt
> ityManager.getTransaction(JTAEntityManager.java:244)
>         at xxx.xxx.xxx.xxx(MetadataDAOImpl.java:65)
>         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
> Method)[:1.6.0_17]
>         at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccess
> orImpl.java:39)[:1.6.0_17]
>         at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMeth
> odAccessorImpl.java:25)[:1.6.0_17]
>         at java.lang.reflect.Method.invoke(Method.java:597)[:1.6.0_17]
>         at
> org.apache.aries.proxy.impl.ProxyHandler$1.invoke(ProxyHandler
> .java:50)
>         at
> org.apache.aries.blueprint.proxy.Collaborator.invoke(Collabora
> tor.java:91)
>         at
> org.apache.aries.proxy.impl.ProxyHandler.invoke(ProxyHandler.java:78)
>         at xxx.xxx.xxx(Unknown Source)
>         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
> Method)[:1.6.0_17]
>         at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccess
> orImpl.java:39)[:1.6.0_17]
>         at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMeth
> odAccessorImpl.java:25)[:1.6.0_17]
>         at java.lang.reflect.Method.invoke(Method.java:597)[:1.6.0_17]
>         at
> org.apache.aries.proxy.impl.ProxyHandler$1.invoke(ProxyHandler
> .java:50)
>         at
> org.apache.aries.proxy.impl.DefaultWrapper.invoke(DefaultWrapp
> er.java:31)
>         at
> org.apache.aries.proxy.impl.ProxyHandler.invoke(ProxyHandler.java:78)
>         at $Proxy33.saveNewMetadatas(Unknown Source)
>
>
>
>
> --
> View this message in context:
> http://openjpa.208410.n2.nabble.com/OpenJPA-transactions-tp741
> 1924p7411924.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>


Maybe you need:

        <persistence-unit name="metadataPersistenceUnit" transaction-type="RESOURCE_LOCAL">

Instead of

      <persistence-unit name="metadataPersistenceUnit" transaction-type="JTA">



John

----

Who is General Failure, and why is he reading my hard disk?


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: AW: OpenJPA transactions

javidelgadillo
Bobitz,

Thanks for the suggestion, but that didn't make a difference.

As an FYI, here's the output when I start Karaf:
31  metadataPersistenceUnit  TRACE  [FelixStartLevel] openjpa.Runtime - Setting the following properties from "?" into configuration: {javax.persistence.provider=org.apache.openjpa.persistence.PersistenceProviderImpl, openjpa.RuntimeUnenhancedClasses=unsupported, javax.persistence.sharedCache.mode=UNSPECIFIED, openjpa.Log=DefaultLevel=TRACE, PersistenceVersion=1.0, openjpa.Id=metadataPersistenceUnit, openjpa.ConnectionFactoryMode=managed, openjpa.ConnectionFactory=org.apache.aries.jpa.container.unit.impl.DelayedLookupDataSource@556aa9, javax.persistence.validation.mode=AUTO, openjpa.jdbc.SynchronizeMappings=buildSchema, openjpa.ManagedRuntime=jndi(TransactionManagerName=osgi:service/javax.transaction.TransactionManager), openjpa.TransactionMode=managed, openjpa.MetaDataFactory=jpa(Types=MetadataEntity), openjpa.ClassResolver=org.apache.openjpa.persistence.PersistenceUnitInfoImpl$ClassResolverImpl@157c76a, openjpa.ConnectionFactory2=org.apache.aries.jpa.container.unit.impl.DelayedLookupDataSource@1cdbaf7}
46  metadataPersistenceUnit  TRACE  [FelixStartLevel] openjpa.Runtime - No cache marshaller found for id org.apache.openjpa.conf.MetaDataCacheMaintenance.
202  metadataPersistenceUnit  TRACE  [FelixStartLevel] openjpa.MetaData - Scanning resource "META-INF/orm.xml" for persistent types.
202  metadataPersistenceUnit  TRACE  [FelixStartLevel] openjpa.MetaData - The persistent unit root url is "null"
202  metadataPersistenceUnit  TRACE  [FelixStartLevel] openjpa.MetaData - parsePersistentTypeNames() found [MetadataEntity].
202  metadataPersistenceUnit  TRACE  [FelixStartLevel] openjpa.MetaData - Found 1 classes with metadata in 15 milliseconds.
0  metadataPersistenceUnit  TRACE  [FelixStartLevel] openjpa.Runtime - Setting the following properties from "?" into configuration: {openjpa.BrokerFactory=jdbc, javax.persistence.provider=org.apache.openjpa.persistence.PersistenceProviderImpl, openjpa.RuntimeUnenhancedClasses=unsupported, javax.persistence.sharedCache.mode=UNSPECIFIED, openjpa.Log=DefaultLevel=TRACE, PersistenceVersion=1.0, openjpa.Id=metadataPersistenceUnit, openjpa.ConnectionFactoryMode=managed, openjpa.ConnectionFactory=org.apache.aries.jpa.container.unit.impl.DelayedLookupDataSource
@556aa9, javax.persistence.validation.mode=AUTO, openjpa.jdbc.SynchronizeMappings=buildSchema, openjpa.ManagedRuntime=jndi(TransactionManagerName=osgi:service/javax.transaction.TransactionManager), openjpa.TransactionMode=managed, openjpa.BrokerImpl=non-finalizing, openjpa.MetaDataFactory=jpa(Types=MetadataEntity), openjpa.ClassResolver=org.apache.openjpa.persistence.PersistenceUnitInfoImpl$ClassResolverImpl@157c76a, openjpa.ConnectionFactory2=org.apache.aries.jpa.container.unit.impl.DelayedLookupDataSource@1cdbaf7}
109  metadataPersistenceUnit  TRACE  [FelixStartLevel] openjpa.Runtime - Not creating a ValidatorImpl because this app is using the JPA 1.0 Spec
203  metadataPersistenceUnit  TRACE  [FelixStartLevel] openjpa.Runtime - org.apache.openjpa.persistence.PersistenceProviderImpl@1f543bb creating container org.apache.openjpa.persistence.EntityManagerFactoryImpl@131cfec for PU metadataPersistenceUnit.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: AW: OpenJPA transactions

Jeremy Bauer
I'm not very familiar with how transaction management works within
Aries, but for JPA in general, if you are using JTA transactions you
should not use em.getTransaction().begin().  That API should only be
used for resource local transactions (non-JTA, direct to the
database).  It looks like the Aries site has some good JPA related
information here:  http://aries.apache.org/modules/jpaproject.html.
In particular, take a look at incidentDAO.  That bean has a
container-managed transactional element specified.  I suspect you'll
need to do something similar in your application.

hth,
Jeremy

On Wed, Mar 28, 2012 at 11:54 AM, javidelgadillo <[hidden email]> wrote:

> Bobitz,
>
> Thanks for the suggestion, but that didn't make a difference.
>
> As an FYI, here's the output when I start Karaf:
> 31  metadataPersistenceUnit  TRACE  [FelixStartLevel] openjpa.Runtime -
> Setting the following properties from "?" into configuration:
> {javax.persistence.provider=org.apache.openjpa.persistence.PersistenceProviderImpl,
> openjpa.RuntimeUnenhancedClasses=unsupported,
> javax.persistence.sharedCache.mode=UNSPECIFIED,
> openjpa.Log=DefaultLevel=TRACE, PersistenceVersion=1.0,
> openjpa.Id=metadataPersistenceUnit, openjpa.ConnectionFactoryMode=managed,
> openjpa.ConnectionFactory=org.apache.aries.jpa.container.unit.impl.DelayedLookupDataSource@556aa9,
> javax.persistence.validation.mode=AUTO,
> openjpa.jdbc.SynchronizeMappings=buildSchema,
> openjpa.ManagedRuntime=jndi(TransactionManagerName=osgi:service/javax.transaction.TransactionManager),
> openjpa.TransactionMode=managed,
> openjpa.MetaDataFactory=jpa(Types=MetadataEntity),
> openjpa.ClassResolver=org.apache.openjpa.persistence.PersistenceUnitInfoImpl$ClassResolverImpl@157c76a,
> openjpa.ConnectionFactory2=org.apache.aries.jpa.container.unit.impl.DelayedLookupDataSource@1cdbaf7}
> 46  metadataPersistenceUnit  TRACE  [FelixStartLevel] openjpa.Runtime - No
> cache marshaller found for id
> org.apache.openjpa.conf.MetaDataCacheMaintenance.
> 202  metadataPersistenceUnit  TRACE  [FelixStartLevel] openjpa.MetaData -
> Scanning resource "META-INF/orm.xml" for persistent types.
> 202  metadataPersistenceUnit  TRACE  [FelixStartLevel] openjpa.MetaData -
> The persistent unit root url is "null"
> 202  metadataPersistenceUnit  TRACE  [FelixStartLevel] openjpa.MetaData -
> parsePersistentTypeNames() found [MetadataEntity].
> 202  metadataPersistenceUnit  TRACE  [FelixStartLevel] openjpa.MetaData -
> Found 1 classes with metadata in 15 milliseconds.
> 0  metadataPersistenceUnit  TRACE  [FelixStartLevel] openjpa.Runtime -
> Setting the following properties from "?" into configuration:
> {openjpa.BrokerFactory=jdbc,
> javax.persistence.provider=org.apache.openjpa.persistence.PersistenceProviderImpl,
> openjpa.RuntimeUnenhancedClasses=unsupported,
> javax.persistence.sharedCache.mode=UNSPECIFIED,
> openjpa.Log=DefaultLevel=TRACE, PersistenceVersion=1.0,
> openjpa.Id=metadataPersistenceUnit, openjpa.ConnectionFactoryMode=managed,
> openjpa.ConnectionFactory=org.apache.aries.jpa.container.unit.impl.DelayedLookupDataSource
> @556aa9, javax.persistence.validation.mode=AUTO,
> openjpa.jdbc.SynchronizeMappings=buildSchema,
> openjpa.ManagedRuntime=jndi(TransactionManagerName=osgi:service/javax.transaction.TransactionManager),
> openjpa.TransactionMode=managed, openjpa.BrokerImpl=non-finalizing,
> openjpa.MetaDataFactory=jpa(Types=MetadataEntity),
> openjpa.ClassResolver=org.apache.openjpa.persistence.PersistenceUnitInfoImpl$ClassResolverImpl@157c76a,
> openjpa.ConnectionFactory2=org.apache.aries.jpa.container.unit.impl.DelayedLookupDataSource@1cdbaf7}
> 109  metadataPersistenceUnit  TRACE  [FelixStartLevel] openjpa.Runtime - Not
> creating a ValidatorImpl because this app is using the JPA 1.0 Spec
> 203  metadataPersistenceUnit  TRACE  [FelixStartLevel] openjpa.Runtime -
> org.apache.openjpa.persistence.PersistenceProviderImpl@1f543bb creating
> container org.apache.openjpa.persistence.EntityManagerFactoryImpl@131cfec
> for PU metadataPersistenceUnit.
>
>
> --
> View this message in context: http://openjpa.208410.n2.nabble.com/OpenJPA-transactions-tp7411924p7414446.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
Loading...