users@glassfish.java.net

Re: how to persist a new entity that refers to already existing entity

From: gufiya <gufiya_at_hotmail.com>
Date: Sun, 1 Mar 2009 12:21:43 -0800 (PST)

Suppose I have 7 fields referring from "emp" to other classes like
"department", "address", "boss" etc.
Using this approach I would have to perform 7 merges before the persist...
that is, 7 (potential) additional queries for one insert statement.

Isn't any other way to deal with this issue, except merge?

(ohh, and of course I can always write the "INSERT" statement myself, but
this misses the whole point of JPA...)


Wolfram Rittmeyer-2 wrote:
>
> gufiya wrote:
>> Thanks for the answers.
>> Indeed, merge() sounds better than explicit find() operation.
>> But still, doesn't it mean an additional access to the database?
>> One underlying query for merge() and another for persist()?
>
> Not necessarily. The EntityManager first looks if it already contains a
> managed object of the same type with the same identity. If so the state
> of your detached object is copied to the managed object and persisted at
> the end of the transaction (if no rollback occurs).
>
> --
> Wolfram Rittmeyer
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>
>
>

-- 
View this message in context: http://www.nabble.com/how-to-persist-a-new-entity-that-refers-to-already-existing-entity-tp22271066p22277454.html
Sent from the java.net - glassfish users mailing list archive at Nabble.com.