2 Replies Latest reply on Jul 12, 2006 9:07 AM by Klas Ekwall

    Problem registering JTA with Hibernate (JBossCache)

    Klas Ekwall Newbie

      Hi,
      I have a configuration using TreeCache + Hibernate + Spring. I it almost working but I am not able to get the cache work with JBoss JTA. The problem seems to be that the I am not able to locate the JBoss TransactionManager when I deploy. Maybe this is not the right place to this post but I believe the problem must somehow be related to how I configure JBoss JTA and lookup of the JTA jndi resource. Any help would be appreciated.

      The configuration file in Spring...

      <!-- Reference to the MySqlDS defined in JBoss -->
       <bean id="mySqlDS" class="org.springframework.jndi.JndiObjectFactoryBean">
       <property name="jndiName" value="MySqlDS"/>
       </bean>
      
       <!-- Hibernate configuration -->
       <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
       <property name="dataSource" ref="mySqlDS"/>
       <property name="schemaUpdate" value="true"/>
       <property name="mappingResources">
       <list>
       <value>hibernate/userdomain.hbm.xml</value>
       <value>hibernate/systemdomain.hbm.xml</value>
       </list>
       </property>
       <property name="hibernateProperties">
       <props>
       <prop key="hibernate.dialect">${xtrade.hibernate.dialect}</prop>
       <prop key="hibernate.showsql">${xtrade.hibernate.showsql}</prop>
       <!-- <prop key="hibernate.hbm2ddl.auto">${xtrade.hibernate.hbm2ddl.auto}</prop> -->
       <prop key="hibernate.cache.provider_class">${xtrade.hibernate.cache.provider}</prop>
       <prop key="hibernate.cache.use_query_cache">true</prop>
       <prop key="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</prop>
       <prop key="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</prop>
       </props>
       </property>
       <!-- <property name="jtaTransactionManager" ref="jbossTxManager"/> -->
       </bean>
      
      


      I have bundled the treecache.xml with the deployed JAR-file and I works ok when deployed outside JBoss (but without JTA).

       <!-- ==================================================================== -->
       <!-- Defines TreeCache configuration -->
       <!-- ==================================================================== -->
       <mbean code="org.jboss.cache.TreeCache" name="jboss.cache:service=TreeCache">
       <depends>jboss:service-Naming</depends>
       <depends>jboss:service-TransactionManager</depends>
       <attribute name="ClusterName">xtradeCluster</attribute>
       <attribute name="CacheMode">REPL_ASYNC</attribute>
       <attribute name="LockAcquisitionTimeout">15000</attribute>
       <attribute name="FetchStateOnStarup">true</attribute>
       ....
      


      And here is the exception..
      22:50:15,233 INFO [STDOUT] 22:50:15,231 ERROR [[/xtrade-web]] Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
      org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [dao-config.xml]: Invocation of init method failed; nested exception is org.hibernate.cache.CacheException: org.hibernate.HibernateException: Could not locate TransactionManager
      Caused by:
      org.hibernate.cache.CacheException: org.hibernate.HibernateException: Could not locate TransactionManager
       at org.hibernate.cache.TreeCacheProvider.start(TreeCacheProvider.java:58)
       at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:169)
       at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1005)
       at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:871)
      ...
      Caused by: org.hibernate.HibernateException: Could not locate TransactionManager
       at org.hibernate.transaction.JNDITransactionManagerLookup.getTransactionManager(JNDITransactionManagerLookup.java:26)
       at org.hibernate.cache.TreeCacheProvider.start(TreeCacheProvider.java:53)
       ... 152 more
      Caused by: javax.naming.NameNotFoundException: TransactionManager not bound
       at org.jnp.server.NamingServer.getBinding(NamingServer.java:529)
      
      



      I would really love to see a code example with a working configuration for how to setup TreeCache + Hibernate + Spring.