Atomikos Forum

Atomikos, JPA+JTA+Spring - Could not find UserTransaction

Hi,

I already posted my problem on another forum:
http://forum.springsource.org/showthread.php?123032-Atomikos-Hibernate%28JPA%29-and-Spring-Could-not-find-UserTransaction-in-JNDI

Since then, I upgraded atomikos to 3.7.0 but didn't get any improvements.

I also read others posts that seems related to my problem:
DidierD Send private email
Tuesday, February 28, 2012
 
 
[previous post comitted to soon]
Hi,

I already posted my problem on another forum:
http://forum.springsource.org/showthread.php?123032-Atomikos-Hibernate%28JPA%29-and-Spring-Could-not-find-UserTransaction-in-JNDI

All my configuration files are mentionned there.

Since then, I upgraded atomikos to 3.7.0 but didn't get any improvements.

I also read others posts that seems related to my problem:
default82df.html?community.6.1311.4

I think my immediate problem is to get my application to work without JNDI. Is it really possible?

Thnaks,

Didier D
DidierD Send private email
Tuesday, February 28, 2012
 
 
Your configuration is wrong.

You should not use this property if you use JTA in current versions of hibernate (afaik 3.5+, 4.x):

hibernate.transaction.factory_class

If you use JTA + CMT Transactions via Spring all is well without, it does even break if you use this property.
See Atomikos Wiki too.
If you want to specify the property use this factory (which is the default anyway);

org.hibernate.transaction.CMTTransactionFactory


See here too:

default82df.html?community.6.2550.5

Same problem there, solution above, should work, give it a try.
Torsten Krah Send private email
Tuesday, February 28, 2012
 
 
Thank you for our reply.
I removed the "hibernate.transaction.factory_class" property and no longer get the JNDI related error.
(since I use Hibernate 3.2.5GA, setting this property to "org.hibernate.transaction.CMTTransactionFactory" didn't work).

Now I am facing a "javax.persistence.TransactionRequiredException: no transaction is in progress" when I call entityManager.flush()

    @PersistenceContext(unitName = "MyPU")
    private EntityManager entityManager;

    @Transactional(readOnly = false, propagation = Propagation.REQUIRED)
    public void foo() {
        final Foo c = new Foo();
        getEntityManager().persist(c);
        getEntityManager().flush();
    }

Going into debug, I do see a call to org.springframework.transaction.interceptor.TransactionInterceptor.invoke(), which shows the a JTA Transaction is created, but why doesn't hibernate see it?

Didier D
DidierD Send private email
Wednesday, February 29, 2012
 
 
Hm maybe you can upgrade to 3.6.x to get the CMT one.
In case this factory is not there, you still have to use the AtomikosFactory provided by Atomikos.
As Workaround try not to use the UserTransaction object directly - remove it from your configuration.
Instead inject for the platform JTATransactionManager @Spring for the userTransaction property the AtomikosTransaction Manager itself - does implement userTransaction interface too.


<bean id="txManager.global.main" class="org.springframework.transaction.jta.JtaTransactionManager"
          depends-on="userTransactionService">
      <property name="transactionManager" ref="AtomikosTransactionManager" />
      <property name="userTransaction" ref="AtomikosTransactionManager" />
    </bean>

Give it a try please. If it does not help tell again, i'll take a deeper look at it than (in this case, please tell me which Hibernate, JPA and Spring version you are using, thx).
Torsten Krah Send private email
Thursday, March 01, 2012
 
 
Hi,

I looked to upgrade to Hibernate 3.6.x, but I rolled back and decided to keep the actual version because of the amount or legacy code I would have to test and fix.

So I tried your suggestion and use 'AtomikosTransactionManager' both as transactionManager and userTransaction properties. As a result, I no longer get the "no transaction is in progress" error, but I still need to call entiyManager.flush() to see queries on the database. So I think Hibernate is still not in the transaction.

If you want, I will prepare a "as small as possible" test case to reproduce this behaviour without all the dependencies to my legacy code.

The versions I use are:
hibernate-3.2.5.ga.jar
hibernate-annotations-3.3.1.GA.jar
hibernate-commons-annotations-3.0.0.ga.jar
hibernate-entitymanager-3.3.1.ga.jar
hibernate-validator-3.0.0.ga.jar
+ Spring 2.5.1
+ atomikos 3.7.0

Didier D
DidierD Send private email
Tuesday, March 06, 2012
 
 
Hi,

Here is a small example maven module: http://dl.free.fr/h35pcoJat
(Zip file; about 33kb)

I am not sure yet that the behavior is exactly the same as in my original
The DB_Schema.sql file contains the SQL tables definitions to create the test tables on the two database (same schema for both databases)
You will hav to modify src\test\resources\properties\db-config.properties to configure the database access.

There is something that bugs me : I have noticed while doing this test case that the "NoInitialContext" exceptions are not completly gone. They still occur when commiting the transaction:

org.hibernate.TransactionException: Could not find UserTransaction in JNDI:
    at org.hibernate.transaction.JTATransaction.<init>(JTATransaction.java:64)
    at org.hibernate.transaction.JTATransactionFactory.createTransaction(JTATransactionFactory.java:57)
    at org.hibernate.jdbc.JDBCContext.getTransaction(JDBCContext.java:193)
    at org.hibernate.impl.SessionImpl.getTransaction(SessionImpl.java:1315)
    at org.hibernate.ejb.EntityManagerImpl.close(EntityManagerImpl.java:61)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.java:346)
    at $Proxy24.close(Unknown Source)
    at org.springframework.orm.jpa.EntityManagerFactoryUtils$EntityManagerSynchronization.beforeCompletion(EntityManagerFactoryUtils.java:349)
    at org.springframework.transaction.support.TransactionSynchronizationUtils.triggerBeforeCompletion(TransactionSynchronizationUtils.java:60)
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.triggerBeforeCompletion(AbstractPlatformTransactionManager.java:895)
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:693)
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:678)
    at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:319)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:116)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
    at $Proxy21.insertFooBar(Unknown Source)
    at test.multipu.services.ServicesTest.testCorrespondancesDB2(ServicesTest.java:141)


I will look deeper tomorrow.

Didier D
DidierD Send private email
Tuesday, March 06, 2012
 
 
Your archive is not really self contained. So thx to your version listing + pom i modified my own test project and test it.
Works fine here - no probs so far.
Don't know where at you test case the problem is; its really hard to get your example running.

http://fachschaft.imn.htwk-leipzig.de/~tkrah/atomikos/hibernate-test.7z

My example - used your versions provided.
Run TxPerformanceTester - hope this one helps to find the problem at your config.
Torsten Krah Send private email
Thursday, March 08, 2012
 
 
Great news!
Thanks to your test case, I was able to compare your config from mine.

Il seems that I had one missing property in the EntityManagerFactory definition:
    <entry key="javax.persistence.transactionType" value="jta"/>

Now that I define this object like this, I no longer have problems :
<bean id="entityManagerFactoryGlobalMain"
    class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="persistenceUnitManager" ref="persistenceUnitManager.global.main" />
    <property name="persistenceUnitName" value="MyPU" />
    <property name="persistenceProviderClass" value="org.hibernate.ejb.HibernatePersistence" />
    <property name="jpaVendorAdapter">
        <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
    </property>
    <property name="jpaPropertyMap">
        <map>
        <entry key="hibernate.dialect" value="org.hibernate.dialect.SQLServerDialect" />
        <entry key="hibernate.cache.use_second_level_cache" value="false" />
        <entry key="hibernate.show_sql" value="${hibernate.show_sql}" />
        <entry key="hibernate.generate_statistics" value="${hibernate.generate_statistics}" />
        <!-- JTA -->
        <entry key="hibernate.connection.release_mode" value="after_statement"/>
        <entry key="hibernate.current_session_context_class" value="jta"/>
        <entry key="javax.persistence.transactionType" value="jta"/>
        <entry key="hibernate.transaction.manager_lookup_class" value="com.atomikos.icatch.jta.hibernate3.TransactionManagerLookup"/>
        </map>
    </property>
</bean>

It seems that this property is very much like the transaction-type="JTA" property we can mention in the persistence.xml file, but afak, this property had to be used along with the "<jta-data-source></jta-data-source>" tag which mention the JNDI datasource name.

I still have some tests to run to validate the whole thing, but that is a relief to take a step foreward after two or three weeks or problems...

Thanks you again,

Didier D
DidierD Send private email
Thursday, March 08, 2012
 
 

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics