openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Patrick Linskey" <>
Subject Re: Extended Persistence Context in multi-threaded app
Date Tue, 29 Jan 2008 19:39:12 GMT
If you want to allow multiple concurrent transactions, you'll need to
have multiple EntityManagers. For example, if you want a given network
operation to happen in a separate transaction while other
transactional work is happening, you'll need a separate EM for that
network operation. You can probably avoid this complexity if you defer
all the database work until the end of the network operation, but the
right answer will really depend on what you want your business process
to look like.

If you end up with multiple EMs, you can register a
TransactionListener to notify the main GUI EM when a different EM
modifies data.


On Jan 29, 2008 9:39 AM, ktj <> wrote:
> Regarding the relationship of the EntityManager to a Transaction: since there
> is a one-to-one EntityManager-to-Transaction relationship, and we will only
> have one EntityManager, it seems that, for us, transactions will be similar
> to flush?
> Assuming we have two Entities, a and b,
> // modify A outside 'transaction'
> a.setFoo...
> EntityTransaction t = em.getTransaction();
> t.begin();
> // modify B inside transaction
> b.setBar...
> t.commit(); // commits changes to a and b
> -or-
> t.rollback(); // rolls back changes to a and b
> Is this correct?
> If this is correct, why does 'flush' need a transaction?
> (EntityManager.flush throws TransactionRequiredException otherwise)
> --
> View this message in context:
> Sent from the OpenJPA Users mailing list archive at

Patrick Linskey
202 669 5907

View raw message