Is there a way one EntityManager can participate smoothely in multiple concurrent transactions?
Well, not that concurrent. Something like:
- Start tx 1
- Do stuff in tx 1
- Start tx 2
- Do stuff in tx 2
- Commit tx 2
- Join tx 1 back
- Do stuff in tx 1
- Commit tx 1
with steps followed one by one not overlapping.
Separate transactions? No, it can not.
Attempting to call EntityTransaction.begin() on a currently active transaction (which is what you would have to do, diretly or indirectly) will result in
IllegalStateExceptionbeing thrown.Unit of work / transaction scope concepts are explained in detail in the Hibernate EntityManager manual.