Can a single EntityManager (Hibernate) participate in multiple concurrent transactions?
-
21-09-2019 - |
Question
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.
Solution
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 IllegalStateException
being thrown.
Unit of work / transaction scope concepts are explained in detail in the Hibernate EntityManager manual.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow