views:

343

answers:

1

Hi!

Is there a way one EntityManager can participate smoothely in multiple concurrent transactions?

Well, not that concurrent. Something like:

  1. Start tx 1
  2. Do stuff in tx 1
  3. Start tx 2
  4. Do stuff in tx 2
  5. Commit tx 2
  6. Join tx 1 back
  7. Do stuff in tx 1
  8. Commit tx 1

with steps followed one by one not overlapping.

+1  A: 

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.

ChssPly76