2012-08-14 42 views
0

我在加入JMS功能(通過ActiveMQ的)到現有的春/ Hibernate的Web應用程序的過程很。因此,我想將XA/JTA功能添加到此應用程序,以便我可以管理跨越數據存儲和消息代理的事務(使用Spring)。在未受管理的容器中使用XA/JTA的Spring + JPA/Hibernate + ActiveMQ。沒有看到錯誤,但沒有看到數據被提交到數據庫

我已經成功地與ActiveMQ的集成,但是,我正在與結合XA/JTA到應用程序中的問題。具體來說,沒有數據被插入/更新到底層數據庫中(儘管我在交易過程中沒有看到錯誤/異常)。

細節:春3.1.2.RELEASE,休眠3.6.10.Final,ActiveMQ的5.6.0

我使用Spring數據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 

我希望能找到誰已經成功地建立了事務管理這樣一個春天XA/JTA應用誰可以提供一些建議,以什麼我可能做不正確(或失蹤)。我基本上遵循this article的處方(從Atomikos案例的Atomikos網站收集了一些額外的信息)。

感謝您的啓發,你可以提供。

更新:我解決我的問題。問題在於我沒有使用persistence.xml文件(而是在使用setPackagesToScan方法設置LocalContainerEntityManagerFactoryBean時以編程方式配置持久性單元)。由於沒有persistence.xml文件(具體來說,沒有持久性單元元素的事務類型屬性),持久性單元確實正在加載我的@Entity類,事務類型被默認爲RESOURCE_LOCAL(這是非Java EE容器的默認值)。我現在明確提供了一個persistence.xml文件,並明確設置了transaction-type =「JTA」。

回答

0

你仍然可以使用LocalContainerEntityManagerFactoryBean只要你有作爲的jpaPropertyMap屬性傳遞的屬性值之一:

<prop key="javax.persistence.transactionType">JTA</prop> 
相關問題