既存の Spring/Hibernate Web アプリケーションに JMS 機能を (ActiveMQ 経由で) 追加しようとしています。したがって、データ ストアとメッセージ ブローカーの両方にまたがるトランザクション (Spring を使用) を管理できるように、このアプリに XA/JTA 機能を追加したいと考えています。
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 アプリケーションをトランザクション管理用に正常にセットアップした人を見つけて、私が間違っている (または不足している) ことについていくつかの提案を提供できる人を見つけたいと思っています。私は基本的に、この記事の処方箋に従いました (Atomikos のケースについては、Atomikos の Web サイトから収集した情報を少し追加します)。
あなたが提供できる啓発に感謝します。
更新:問題を解決しました。問題は、persistence.xml ファイルを使用していなかったことです (代わりに、setPackagesToScan メソッドを使用して LocalContainerEntityManagerFactoryBean をセットアップするときにプログラムで永続化ユニットを構成していました)。persistence-unit は実際に @Entity クラスを適切にロードしていましたが、persistence.xml ファイルが存在しないため (具体的には、persistence-unit 要素の transaction-type 属性が存在しないため)、transaction-type はデフォルトで次のように設定されていました。 RESOURCE_LOCAL (非 Java EE コンテナーのデフォルト)。現在、persistence.xml ファイルを明示的に提供し、transaction-type="JTA" を明示的に設定しています。