javaspringhibernatetransactionsatomikos

org.hibernate.HibernateException: No TransactionManagerLookup specified on hibernate upgrade


I am running spring 4.1.4, hibernate 4.3.8, atomikos 3.9.3, java 8, tomcat 8.

I see the above exception in localhost.log when I start my server but I'm not sure where to configure the TransactionManagerLookup apart from where I am already configuring it. This wasn't happening before upgrading hibernate so it is most likely a versioning issue. Could anyone help please?

FYI: catalina.out shows nothing useful. Just:

SEVERE [localhost-startStop-1] org.apache.catalina.core.StandardContext.startInternal Error listenerStart
SEVERE [localhost-startStop-1] org.apache.catalina.core.StandardContext.startInternal Context [] startup failed due to previous errors

My appContext defines :

<prop key="hibernate.transaction.factory_class">org.hibernate.engine.transaction.internal.jta.CMTTransactionFactory</prop>
<prop key="hibernate.transaction.manager_lookup_class">com.atomikos.icatch.jta.hibernate3.TransactionManagerLookup</prop>

and the full stack trace is:

22-Jan-2015 10:07:25.734 SEVERE [localhost-startStop-1] org.apache.catalina.core.StandardContext.listenerStart Exception sending context initialized event to listener instance of class com.my.app.web.InitializerListener
 org.hibernate.HibernateException: No TransactionManagerLookup specified
    at org.hibernate.context.internal.JTASessionContext.currentSession(JTASessionContext.java:85)
    at org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:1014)
    at com.my.app.dao.AbstractMyDAO.currentSession(AbstractMyDAO.java:116)
    at com.my.app.dao.AbstractMyDAO.criteria(AbstractMyDAO.java:86)
    at com.my.app.dao.AbstractMyDAO.count(AbstractMyDAO.java:79)
    at com.my.app.initialize.MyInitializerImpl.initializeApplicaiton(MyInitializerImpl.java:69)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
    at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
    at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
    at com.sun.proxy.$Proxy220.initializeApplicaiton(Unknown Source)
    at com.my.app.web.MyInitializerListener.contextInitialized(MyInitializerListener.java:42)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4772)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5196)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:725)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:701)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:714)
    at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:917)
    at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1701)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

EDIT: The Atomikos Transaction manager is configured as such

<bean id="atomikosTransactionManager" class="com.atomikos.icatch.jta.UserTransactionManager" init-method="init" destroy-method="close">
    <property name="forceShutdown" value="true" />
    <!--  in secs -->
    <property name="transactionTimeout" value="300"/>
</bean>
<bean id="atomikosUserTransaction" class="com.atomikos.icatch.jta.UserTransactionImp">
    <!--  in secs -->
    <property name="transactionTimeout" value="300" />
</bean>
<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
    <property name="transactionManager" ref="atomikosTransactionManager" />
    <property name="userTransaction" ref="atomikosUserTransaction" />
    <property name="transactionSynchronizationName" value="SYNCHRONIZATION_ON_ACTUAL_TRANSACTION" />
    <property name="allowCustomIsolationLevels" value="true"/>
</bean>

EDIT 2:

I think I need to clarify things a bit here. I have a DAO object called AbstractMyDAO (as you can see from the stack). In this object is defined a session factory

@Autowired
private SessionFactory mySessionFactory;

when currentSession is called the above error is thrown because hibernate cannot find the transaction manager lookup associated with this session factory.

public Session currentSession() {
    return mySessionFactory.getCurrentSession();
}

This session factory is defined in my app context file as such:

<bean id="mySessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">

    <property name="dataSource">
        <ref bean="myDataSource" />
    </property>
    <property name="annotatedClasses">
        <list>
            <value>some values... </value>
            ...
        </list>
    </property>
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">
                ${gst.hibernate.dialect}
            </prop>
            <prop key="query.factory_class">
                org.hibernate.hql.ast.ASTQueryTranslatorFactory
            </prop>
            <prop key="hibernate.max_fetch_depth">3</prop>
            <prop key="hibernate.show_sql">${my.hibernate.showsql}</prop>
            <prop key="hibernate.cache.use_query_cache">true</prop>
            <prop key="hibernate.cache.use_second_level_cache">true</prop>
            <prop key="hibernate.cache.use_structured_entries">true</prop>
            <prop key="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory</prop>
            <prop key="net.sf.ehcache.configurationResourceName">${ehcache.my.persist.config}</prop>
            <prop key="hibernate.connection.isolation">3</prop>
            <prop key="connection.release_mode">auto</prop>
            <prop key="hibernate.current_session_context_class">jta</prop>
            <prop key="hibernate.transaction.factory_class">org.hibernate.engine.transaction.internal.jta.CMTTransactionFactory</prop>
            <prop key="hibernate.transaction.manager_lookup_class">com.atomikos.icatch.jta.hibernate3.TransactionManagerLookup</prop>
            <prop key="hibernate.search.default.directory_provider">filesystem</prop>
            <prop key="hibernate.search.default.indexBase">/var/log/my/lucene/indexes</prop>
        </props>
    </property>
</bean>

As you can see, the property hibernate.transaction.manager_lookup_class is being defined but can't be found when the bean is created and I have no idea why. Has the configuration changed?

EDIT 3: When I debug: final JtaPlatform jtaPlatform = factory().getServiceRegistry().getService( JtaPlatform.class );

It returns a NoJTAPlatform. I guess this is my problem.

EDIT 4: There doesn't seem to be anything that implements JtaPlatform that is suitable for tomcat or am I being mental?


Solution

  • The answer to my question is here.

    "In Hibernate 4.3 the long deprecated TransactionManagerLookup got removed. Now the JTA provider must implement org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform."