openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ljnelson <>
Subject Re: State Management, changed properties on detached object not saving
Date Wed, 01 Jul 2009 14:39:24 GMT

On Wed, Jul 1, 2009 at 10:03 AM, Daryl Stultz (via Nabble) <<>
> wrote:

> To be a little more clear, looks like this:
> EntityManager em = getEntityManager();
> boolean alreadyInTransaction = em.getTransaction().isActive();

if (! alreadyInTransaction) em.getTransaction().begin();

if (getId() == null) em.persist(this);

else em.merge(this);
if (! alreadyInTransaction) em.getTransaction().commit();

I have to admit to only cursorily (is that a word?) scanning this, but
remember that merge() has a return value, and the return value supersedes
the value you passed into it.

You need to follow this pattern when merging:

final X newThing = em.merge(oldThing);

...and then "throw out" oldThing, since it is effectively no longer valid.

Given that you are merge()ing "this", that might be difficult.  :-D

I hope that helps at least somewhat.  Good luck.


View this message in context:
Sent from the OpenJPA Users mailing list archive at

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message