There is an MDB and a sequence of stateless EJBs to do some work with message (WAS 7.0, Java EE 5, EJB 3.0, JPA).
Sequence (using CMT):
- MDB accepts message
- MDB persists entity with the message details
- MDB calls EJB 1 passing entities ID,
- EJB1 does its piece of work with the message, depending on whether EJB1 succeed or not it calls
- EJB2 or EJB5 passing the ID
- EJB2 does its piece of ...
and so on till the last EJB (running time is several minutes).
All of those happens in one transaction: so if something is thrown in EJB4 - everything that happened before in this transaction will be rolled back. I've tried to use REQUIRES_NEW for all the subsequent calls but it seems that changes in previous calls is not visible for subsequent calls. Also, transaction becomes to long and sometimes timed out.
I'd like to have separate, independent transactions for:
- A receiving and persisting message
- B processing in EJB1
- C processing in EJB2
.... so if execution of EJB2 failed, message should remain in DB and result of execution in EJB1 should be persisted as well.
So main question is, using CMT - is it possible to have short and indipendent transactions for the sequence?
Some more
- can the transaction originated in MDB be commited independently of the results of the call to EJB1? Moreover -- commited before the call to EJB1..?
- can changes on an entity made inside the MDB be visile inside the call to a EJB1 method with REQUIRES_NEW attribute?
- is there a way except BTM or WorkManager to achieve the goal?