I didn’t find a clear statement whether transactions are propagated for remote calls in Java EE 5. So I tested it by creating two enterprise applications being deployed in different ears to the same JBoss-5.1.0-GA. In short: YES, the transaction is propagated and a rollback on a calling method initiates a rollback on the remote transaction, too. The willing reader might read on in order to get to know the test setup.
Both applications contain a servlet calling a method on a local stateless session bean. The local session bean uses dependency injection in order to gain access to a remote stateless session bean. In both applications the same remote session bean is called, so that calling a remote bean in the same ear as well as calling it from another ear on the same JVM is tested.
The method called on the remote bean simply stores an entity to a database. The method has the transaction attribute
REQUIRED. Both of the local session beans call that method and throw an Exception afterwards. When the respective Servlets are called nothing will be stored to the database, if the Exception is thrown. So the rollback of the transaction in the local session bean rolls back the remote transaction, too. I uploaded the projects, so that you can experiment with them. The Servlets have parameters for steering, whether an exception should be thrown or not. This way you can ensure, that without a rollback the data is really stored to a database. I tested this approach with hsqldb as well as with postgres.
Here is the example project:transactionpropagation.zip
One thought to “Transaction Propagation for Remote calls”