You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by Tim Watts <ti...@earthlink.net> on 2008/01/26 04:13:26 UTC

Basic question: EntityManager.merge() vs .persist()?

Hi,

What's the difference between merge() and persist()? 

They both add the entity to the persistence context; both will insert the 
entity if necessary. merge() seems to insert/update as necessary. If so, then 
why would I ever need persist() since merge() can do everything it can do?

Also, is remove() supposed to remove the entity from the database, the 
persistence context or both?

Re: Basic question: EntityManager.merge() vs .persist()?

Posted by swathi <sw...@gmail.com>.
even though we do not  commit after deleting the row from data table it is
not deleting wihtout commit..which is the same in case of 'remove'
then what is the difference between 'delete' and 'remove'
which is more efficient?
plz make me clear...
thanks



Patrick Linskey-2 wrote:
> 
> persist() inserts "in-place" -- i.e., it inserts the record that you
> call persist() on. merge() inserts a copy, so is less efficient.
> 
> remove() will result in a DELETE statement when the transaction commits.
> 
> -Patrick
> 
> On Jan 25, 2008 7:13 PM, Tim Watts <ti...@earthlink.net> wrote:
>> Hi,
>>
>> What's the difference between merge() and persist()?
>>
>> They both add the entity to the persistence context; both will insert the
>> entity if necessary. merge() seems to insert/update as necessary. If so,
>> then
>> why would I ever need persist() since merge() can do everything it can
>> do?
>>
>> Also, is remove() supposed to remove the entity from the database, the
>> persistence context or both?
>>
> 
> 
> 
> -- 
> Patrick Linskey
> 202 669 5907
> 
> 

-- 
View this message in context: http://n2.nabble.com/Basic-question%3A-EntityManager.merge%28%29-vs-.persist%28%29--tp209964p530622.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.


Re: Basic question: EntityManager.merge() vs .persist()?

Posted by Patrick Linskey <pl...@gmail.com>.
persist() inserts "in-place" -- i.e., it inserts the record that you
call persist() on. merge() inserts a copy, so is less efficient.

remove() will result in a DELETE statement when the transaction commits.

-Patrick

On Jan 25, 2008 7:13 PM, Tim Watts <ti...@earthlink.net> wrote:
> Hi,
>
> What's the difference between merge() and persist()?
>
> They both add the entity to the persistence context; both will insert the
> entity if necessary. merge() seems to insert/update as necessary. If so, then
> why would I ever need persist() since merge() can do everything it can do?
>
> Also, is remove() supposed to remove the entity from the database, the
> persistence context or both?
>



-- 
Patrick Linskey
202 669 5907