在Tomcat中将JBoss Narayana事务与Spring Data JPA集成

时间:2017-08-21 14:22:24

标签: java hibernate jpa jboss spring-data-jpa

https://github.com/jbosstm/narayana/开始,我尝试使用

org.jboss.narayana.jta:narayana-jta:5.6.2.Final

为Spring实现JTA事务管理器 Data JPA(Hibernate)项目。

虽然Hibernate成功返回使用id保存的对象(由Sequence生成),但数据库中的行实际上并未持久

任何帮助都将受到欢迎。

Spring配置:

<jee:jndi-lookup id="userTxn" jndi-name="java:comp/UserTransaction" />
<jee:jndi-lookup id="tm" jndi-name="java:comp/env/TransactionManager" />
<jee:jndi-lookup id="jtaTxnSyncRegistry" jndi-name="java:comp/env/TransactionSynchronizationRegistry" />


<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
 <property name="userTransaction" ref="userTxn"></property>
 <property name="transactionManager" ref="tm"/>
 <property name="transactionSynchronizationRegistry" 
  ref="jtaTxnSyncRegistry"/>
</bean>

 <tx:annotation-driven transaction-manager="transactionManager"/>


 <bean id="entityManagerFactoryJTA"     class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
    p:persistenceUnitName="myPU_JTA">
    <property name="jpaVendorAdapter">
        <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
    </property>
</bean>

 <jpa:repositories base-package="com.xxx.repository.jta"
    entity-manager-factory-ref="entityManagerFactoryJTA"
    transaction-manager-ref="transactionManager" /> 
apache-tomcat-8.5.16

context.xml

 <Resource name="UserTransaction" auth="Container"
    type="javax.transaction.UserTransaction" factory="com.arjuna.ats.jta.TransactionManager" />

<Transaction    factory="com.arjuna.ats.internal.jta.transaction.arjunacore.UserTransactionImple" />  <!-- auth="Container" -->

<Resource name="TransactionManager" auth="Container" type="javax.transaction.TransactionManager"        factory="com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionManagerImple"></Resource>

<Resource name="TransactionSynchronizationRegistry" auth="Container"  type="javax.transaction.TransactionSynchronizationRegistry"
    factory="com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionSynchronizationRegistryImple" />

1 个答案:

答案 0 :(得分:0)

自Narayana 5.5以来,我们引入了tomcat-jta模块以帮助与tomcat集成。请参见https://github.com/jbosstm/narayana/tree/master/tomcat,所以我认为您需要使用以下context.xml

<!-- Narayana resources -->
<Transaction factory="org.jboss.narayana.tomcat.jta.UserTransactionFactory"/>
<Resource name="TransactionManager" type="javax.transaction.TransactionManager"
          factory="org.jboss.narayana.tomcat.jta.TransactionManagerFactory"/>
<Resource name="TransactionSynchronizationRegistry" type="javax.transaction.TransactionSynchronizationRegistry"
          factory="org.jboss.narayana.tomcat.jta.TransactionSynchronizationRegistryFactory"/>