persistence@glassfish.java.net

Re: merging as the opposite of refresh?

From: John O'Conner <John.Oconner_at_Sun.COM>
Date: Fri, 20 Apr 2007 17:19:56 -0700

Marina Vatkina wrote:
>
> I'm not sure that I understand your point about setting an entity id
> to match the persisted entity. All entity operations are on that
> entity, that is defined by its id.

To try to duplicate a detached object, I created a new entity instance
with the same values as those in the db. Ids are auto-generated in my
test, so I don't have an id param in my entity constructors. To properly
duplicate the db version of the entity, I had to set the id
correctly...and then the merge worked properly. I think this is not the
usual way of getting a detached entity.

I understand now that more common (or correct) ways to get a detached
object might be a deserialized object or even an entity that I keep
around after closing the entity manager. In either of these cases, the
id should already match what's in the db.

My exploration of the API has naturally led me far astray from natural
and customary usages. :)
 But I am learning a lot!

--
John O'Conner