users@glassfish.java.net

Re: persist() and merge() and queries: what affects persistence context?

From: <glassfish_at_javadesktop.org>
Date: Tue, 17 Jun 2008 12:01:00 PDT

> There are 3 options - use extended persistence
> context with a SFSB (but you'll also keep all other
> entities around)

Not an option in my case, I'm afraid.

> call em.find() to check if the
> entity is there in the database

I would like to avoid the extra query if possible. Maybe I can't.

> always call
> em.merge() - it's allowed to be called on a new
> entity

Right, but it creates a new entity and copies state over. In my case, there is some transient state in the entity to be persisted/merged that I want to hang on to.

Sounds like find() is what I want, or brute force try-to-persist, fall-back-to-merge.

Thanks for your help!

Best,
Laird
[Message sent by forum member 'ljnelson' (ljnelson)]

http://forums.java.net/jive/thread.jspa?messageID=280810