Reputation: 1
I am using mdb-jms. I have created an EJB stateless class that has 2 methods. (i) Method insertInput() is annotated as @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW), does an insertion to the table. (ii) method getInput() (transaction attribute set to REQUIRED) throws an exception from DAO layer.
Method insertInput() is invoked first and the method getInput() is called after that from the MDB class.
In the mdb class, the catch block holds the code messagedrivencontext.setRollbacksOnly() set to rollback if there is any exception.
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public void insertInput(Object obj) throws NewDataException {
/**** Invokes a dao method that inserts value into a table ****/
}
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void getInput(Object obj) throws NewDataException {
/*** invokes a DAO method that throws an exception ****/
}
Expectation: The insertion done by the method insertInput() should be available in the table as it is started with a separate transaction. Only insertions done by Method getInput() (if there are any) should be rolled back.
Actual: The insertion done to the db by Method insertInput() is also rolledback from the table even though it was done using a new transaction.
Is this is how it actually should work? If yes, is there a way to rollback only the changes of Method getInput()?
Upvotes: 0
Views: 53
Reputation: 1
The behavior must be as described in your expectation. When the transaction type is REQUIRES_NEW in the inner method, the transaction in the outer method is resumed until the inner transaction is either committed or rollbacked and will not affect the outer transaction outcome.
You should verify that the method insertInput(Object obj) does not throw any unchecked exception.
Upvotes: 0