persistence@glassfish.java.net

merging as the opposite of refresh?

From: John O'Conner <John.Oconner_at_Sun.COM>
Date: Fri, 20 Apr 2007 16:43:12 -0700

Forgive the simplistic questions of a JPA newbie:

I have a simple Player entity and have been successful persisting player
objects to Java DB. However, I'm confused about the merge operation, its
purpose, and its usage.

In trying to understand merge, I've decided that merge() is like
refresh() in some ways (or maybe the opposite of refresh). It pushes an
entity's properties back into the database, overwriting whatever is
there. I noticed that merge() works on the intended database row only if
I've set the entity id to match the persisted entity -- no surprise
there. And all other fields in the row get overwritten with my new
entity values. The term "merge" does confuse me a little -- no merging
of anything seems to occur; the operation simply overwrites the db
record, right?

So two questions:
Is this comparison to refresh a reasonable comparison?
Is the merge operation effectively the same as removing an entity and
persisting it again with the same id?

Thanks,
John O'Conner