Question

I'm using Tomcat7 and need JTA for Infinispan Cache. I am using Spring 3.x with Hibernate 4 (non JPA) and Atomikos for JTA. I can't find a transaction manager look up class in the Atomikos library or docs for Hibernate 4. All examples are for Hibernate version 3 or with use of JPA. Infinispan cannot find a transaction manager.

Here is my config:

 <bean id="myDataSource" class="com.atomikos.jdbc.AtomikosDataSourceBean"
      init-method="init" destroy-method="close">
      <property name="uniqueResourceName" value="rsname" />
      <property name="xaDataSourceClassName"
       value="com.mysql.jdbc.jdbc2.optional.MysqlXADataSource" />
      <property name="xaProperties">
       <props>
        <prop key="URL">${db.url}</prop>
        <prop key="user">${db.user}</prop>
        <prop key="password">${db.pass}</prop>
       </props>
      </property>
      <property name="maxPoolSize" value="50" />
      <property name="minPoolSize" value="20" />

 </bean>


  <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    <property name="dataSource" ref="myDataSource"/>
    <property name="mappingLocations" value="classpath*:hibernate/**/*.hbm.xml" />

    <property name="hibernateProperties">
      <value>
        hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
        hibernate.show_sql=true
        hibernate.cache.region.factory_class=org.hibernate.cache.infinispan.InfinispanRegionFactory
        hibernate.cache.use_query_cache=true
        hibernate.cache.use_second_level_cache=true

      </value>
    </property>
  </bean>

  <bean id="atomikosTransactionManager" class="com.atomikos.icatch.jta.UserTransactionManager"
     init-method="init" destroy-method="close">
  <property name="forceShutdown" value="false" />
 </bean>



 <bean id="atomikosUserTransaction" class="com.atomikos.icatch.jta.J2eeUserTransaction">
  <property name="transactionTimeout" value="300" />
 </bean>

 <tx:annotation-driven />
  <bean id="transactionManager"
            class="org.springframework.transaction.jta.JtaTransactionManager" depends-on="atomikosTransactionManager,atomikosUserTransaction">
   <property name="transactionManager" ref="atomikosTransactionManager" />
   <property name="userTransaction" ref="atomikosUserTransaction" />
   <property name="allowCustomIsolationLevels" value="true" />

  </bean>
  <tx:advice id="txAdvice">
  <tx:attributes>
  <tx:method name="*" rollback-for="Throwable" />
  </tx:attributes>
</tx:advice>
Était-ce utile?

La solution

Looking at the spring docs setting the jtaTransactionManager property on the LocalSessionFactoryBean should take care of things.

<property name="jtaTransactionManager" ref="transactionManager" />

Basically adding that to the definition of your bean should be enough.

Another note about your configuration, you are using <tx:annotation-driven /> so basically your <tx:advice .. /> does nothing only takes up space.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top