Spring + JPA / Hibernate + ActiveMQ与XA / JTA在非托管容器中。没有看到错误,但没有看到数据被提交到数据库

时间:2012-08-14 17:48:45

标签: spring hibernate transactions jta xa

我正在将JMS功能(通过ActiveMQ)添加到现有的Spring / Hibernate Web应用程序中。因此,我想在这个应用程序中添加XA / JTA功能,这样我就可以管理跨越数据存储和消息代理的事务(使用Spring)。

我在ActiveMQ集成方面取得了成功,但是,我遇到了将XA / JTA整合到应用程序中的问题。具体来说,没有数据被插入/更新到底层数据库中(但是,我看到在事务期间没有错误/异常)。

详细信息:Spring 3.1.2.RELEASE,Hibernate 3.6.10.Final,ActiveMQ 5.6.0

我正在使用Spring Data JPA来编写我的DAO接口,然后他们拿起我的LocalContainerEntityManagerFactoryBean来完成他们的CRUD工作。

我尝试过使用Atomikos(5.6.0)和Bitronix(2.1.3)XA / JTA实现。每个都导致相同的行为(没有数据写入底层数据库表)。

我有很多日志记录,如果需要,我当然可以提供日志摘录。并且,配置细节也是如此。在日志中特别注意,Spring似乎表明JTA事务是(试图?)提交。但是,由于缺少写入底层数据库的数据,目前尚不清楚它是否实际完成了提交(但是,我再次看到没有错误表明它没有)。此外,值得注意的是,这个特定的事务--populateSampleData--只涉及数据库资源(根本没有消息代理参与)。

2012-08-14 13:16:09,770 DEBUG [org.springframework.transaction.annotation.AnnotationTransactionAttributeSource] - Adding transactional method 'populateSampleData' with attribute: PROPAGATION_REQUIRED,ISOLATION_DEFAULT; ''
2012-08-14 13:16:09,772 DEBUG [org.springframework.beans.factory.support.DefaultListableBeanFactory] - Returning cached instance of singleton bean 'transactionManager'
2012-08-14 13:16:09,776 DEBUG [org.springframework.transaction.jta.JtaTransactionManager] - Creating new transaction with name [com.teg.saamweb.service.SaamWebServiceTransactional.populateSampleData]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT; ''
2012-08-14 13:16:09,811 DEBUG [org.springframework.orm.jpa.EntityManagerFactoryUtils] - Opening JPA EntityManager
2012-08-14 13:16:09,812 DEBUG [org.springframework.orm.jpa.EntityManagerFactoryUtils] - Registering transaction synchronization for JPA EntityManager
2012-08-14 13:16:09,898 DEBUG [org.springframework.data.repository.core.support.TransactionalRepositoryProxyPostProcessor$CustomAnnotationTransactionAttributeSource] - Adding transactional method 'save' with attribute: PROPAGATION_REQUIRED,ISOLATION_DEFAULT; ''
2012-08-14 13:16:09,899 DEBUG [org.springframework.beans.factory.support.DefaultListableBeanFactory] - Returning cached instance of singleton bean 'transactionManager'
2012-08-14 13:16:09,899 DEBUG [org.springframework.transaction.jta.JtaTransactionManager] - Participating in existing transaction
2012-08-14 13:16:09,964 DEBUG [org.springframework.data.repository.core.support.TransactionalRepositoryProxyPostProcessor$CustomAnnotationTransactionAttributeSource] - Adding transactional method 'save' with attribute: PROPAGATION_REQUIRED,ISOLATION_DEFAULT; ''
2012-08-14 13:16:09,964 DEBUG [org.springframework.beans.factory.support.DefaultListableBeanFactory] - Returning cached instance of singleton bean 'transactionManager'
2012-08-14 13:16:09,964 DEBUG [org.springframework.transaction.jta.JtaTransactionManager] - Participating in existing transaction
2012-08-14 13:16:09,982 DEBUG [org.springframework.data.repository.core.support.TransactionalRepositoryProxyPostProcessor$CustomAnnotationTransactionAttributeSource] - Adding transactional method 'save' with attribute: PROPAGATION_REQUIRED,ISOLATION_DEFAULT; ''
2012-08-14 13:16:09,982 DEBUG [org.springframework.beans.factory.support.DefaultListableBeanFactory] - Returning cached instance of singleton bean 'transactionManager'
2012-08-14 13:16:09,983 DEBUG [org.springframework.transaction.jta.JtaTransactionManager] - Participating in existing transaction
2012-08-14 13:16:09,992 DEBUG [org.springframework.beans.factory.support.DefaultListableBeanFactory] - Returning cached instance of singleton bean 'transactionManager'
2012-08-14 13:16:09,992 DEBUG [org.springframework.transaction.jta.JtaTransactionManager] - Participating in existing transaction
2012-08-14 13:16:09,996 DEBUG [org.springframework.beans.factory.support.DefaultListableBeanFactory] - Returning cached instance of singleton bean 'transactionManager'
2012-08-14 13:16:09,996 DEBUG [org.springframework.transaction.jta.JtaTransactionManager] - Participating in existing transaction
2012-08-14 13:16:10,000 DEBUG [org.springframework.beans.factory.support.DefaultListableBeanFactory] - Returning cached instance of singleton bean 'transactionManager'
2012-08-14 13:16:10,000 DEBUG [org.springframework.transaction.jta.JtaTransactionManager] - Participating in existing transaction
2012-08-14 13:16:10,003 DEBUG [org.springframework.beans.factory.support.DefaultListableBeanFactory] - Returning cached instance of singleton bean 'transactionManager'
2012-08-14 13:16:10,003 DEBUG [org.springframework.transaction.jta.JtaTransactionManager] - Participating in existing transaction
2012-08-14 13:16:10,007 DEBUG [org.springframework.beans.factory.support.DefaultListableBeanFactory] - Returning cached instance of singleton bean 'transactionManager'
2012-08-14 13:16:10,007 DEBUG [org.springframework.transaction.jta.JtaTransactionManager] - Participating in existing transaction
2012-08-14 13:16:10,011 DEBUG [org.springframework.beans.factory.support.DefaultListableBeanFactory] - Returning cached instance of singleton bean 'transactionManager'
2012-08-14 13:16:10,011 DEBUG [org.springframework.transaction.jta.JtaTransactionManager] - Participating in existing transaction
2012-08-14 13:16:10,014 DEBUG [org.springframework.beans.factory.support.DefaultListableBeanFactory] - Returning cached instance of singleton bean 'transactionManager'
2012-08-14 13:16:10,014 DEBUG [org.springframework.transaction.jta.JtaTransactionManager] - Participating in existing transaction
2012-08-14 13:16:10,017 DEBUG [org.springframework.beans.factory.support.DefaultListableBeanFactory] - Returning cached instance of singleton bean 'transactionManager'
2012-08-14 13:16:10,017 DEBUG [org.springframework.transaction.jta.JtaTransactionManager] - Participating in existing transaction
2012-08-14 13:16:10,020 DEBUG [org.springframework.beans.factory.support.DefaultListableBeanFactory] - Returning cached instance of singleton bean 'transactionManager'
2012-08-14 13:16:10,020 DEBUG [org.springframework.transaction.jta.JtaTransactionManager] - Participating in existing transaction
2012-08-14 13:16:10,023 DEBUG [org.springframework.beans.factory.support.DefaultListableBeanFactory] - Returning cached instance of singleton bean 'transactionManager'
2012-08-14 13:16:10,023 DEBUG [org.springframework.transaction.jta.JtaTransactionManager] - Participating in existing transaction
2012-08-14 13:16:10,026 DEBUG [org.springframework.beans.factory.support.DefaultListableBeanFactory] - Returning cached instance of singleton bean 'transactionManager'
2012-08-14 13:16:10,026 DEBUG [org.springframework.transaction.jta.JtaTransactionManager] - Participating in existing transaction
2012-08-14 13:16:10,030 DEBUG [org.springframework.beans.factory.support.DefaultListableBeanFactory] - Returning cached instance of singleton bean 'transactionManager'
2012-08-14 13:16:10,030 DEBUG [org.springframework.transaction.jta.JtaTransactionManager] - Participating in existing transaction
2012-08-14 13:16:10,033 DEBUG [org.springframework.beans.factory.support.DefaultListableBeanFactory] - Returning cached instance of singleton bean 'transactionManager'
2012-08-14 13:16:10,033 DEBUG [org.springframework.transaction.jta.JtaTransactionManager] - Participating in existing transaction
2012-08-14 13:16:10,036 DEBUG [org.springframework.beans.factory.support.DefaultListableBeanFactory] - Returning cached instance of singleton bean 'transactionManager'
2012-08-14 13:16:10,036 DEBUG [org.springframework.transaction.jta.JtaTransactionManager] - Participating in existing transaction
2012-08-14 13:16:10,038 DEBUG [org.springframework.orm.jpa.EntityManagerFactoryUtils] - Closing JPA EntityManager
2012-08-14 13:16:10,039 DEBUG [org.springframework.transaction.jta.JtaTransactionManager] - Initiating transaction commit

我希望找到一个成功设置了这样一个Spring XA / JTA应用程序进行事务管理的人,他可以提供一些关于我可能做错误(或缺失)的建议。我基本上遵循了this article中的处方(在Atomikos案例中从Atomikos网站收集了一些其他信息)。

感谢您提供的任何启发。

更新:我解决了我的问题。问题是我没有使用persistence.xml文件(而是在使用setPackagesToScan方法设置LocalContainerEntityManagerFactoryBean时以编程方式配置持久性单元)。虽然持久性单元确实正确地加载了我的@Entity类,但是由于缺少persistence.xml文件(具体来说,缺少持久性单元元素的transaction-type属性),事务类型被默认为RESOURCE_LOCAL(这是非Java EE容器的缺省值)。我现在明确提供了一个persistence.xml文件,并明确设置了transaction-type =“JTA”。

1 个答案:

答案 0 :(得分:0)

只要您将LocalContainerEntityManagerFactoryBean属性作为属性值之一包含在内,您仍然可以使用jpaPropertyMap

<prop key="javax.persistence.transactionType">JTA</prop>