openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ljnelson <ljnel...@gmail.com>
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) <
ml-user+140370-1665331873@n2.nabble.com<ml-user%2B140370-1665331873@n2.nabble.com>
> wrote:

> To be a little more clear, entity.save() 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.

Best,
Laird

-- 
View this message in context: http://n2.nabble.com/State-Management%2C-changed-properties-on-detached-object-not-saving-tp3188832p3189415.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

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