users@glassfish.java.net

Re: JPA - why persist and merge, why not a sigle save

From: <glassfish_at_javadesktop.org>
Date: Fri, 01 Oct 2010 13:25:11 PDT

Hi

I realize this is very late, but I have just started to work on JPA and I faced the same question that the author of this thread did. I think one of the reasons for two different methods could be this -

With a merge( ) operation, the ORM has to do a SELECT first to identify if a row exists, and then perform an INSERT or an UPDATE to save the data. (Atleast this is what happens with Hibernate as the underlying implementation)
So, if the application knows that it is creating a new instance, it can call the persist( ) directly and avoid the overhead of additional query.
[Message sent by forum member 'shunya']

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