How to synchronize JDBC transactions with Bean Managed User Transactions...
henri_tudor Dec 7, 2012 3:45 AMHi all...
In the scope of a project of ours, we have developped a custom rule engine application based on a JBoss Application Server in version 5.1. All rule processing is done in a stateful Session Bean with Bean Managed Transactions. While processing rules, the session bean relies on regular JDBC connections to query data from external data sources. Before applying rules, the session bean begins a new transaction, all involved JDBC connections are beginning a new transaction as well. After the rules have been applied, the BMT persists the results of rule evaluation in the rule engines database and all involved transactions are either committed or rolled back. All this worked fine. Now, the end user created a new JDBC data source, pointing to the rule engines database itself. The idea was to define a rule that would check whether a previous rule evaluation generated some specific result. Unfortunately, this doesn't work as expected. Looking at the rule engines log file, I noticed that the results of a previous evaluation are not immediately visible for the next transactions but appear to be updated with a certain latency. The JDBC transactions are in READ_COMMITTED isolation, which explains why the updated results are visible in the same transaction. What bugs me is the fact that, even though the Bean Managed Transaction after commit returns STATUS_NO_TRANSACTION, which indicates that the commit was completed successfully, it looks as if behind the scenes the actual database commit process is either being cached, postponed or somehow delayed. From the point of view of the transaction manager this makes sense, given that fact, that the Transaction Manager assumes that all transactions are managed by himself and decides when to commit which piece of data. My question is, is there a way, to attach external JDBC transactions to the transaction manager so that he is aware of them and may include them in his decision process ? Is there a way to synchronize with the actual db commit process ? Has anyone tried something similar ?
Many thanks in advance for reading all this and your feedback....