1

Both will update the persistent state but

  • merge will return attached instance letting the given one unchanged.
  • update will attach the given instance

my question is so : will JPA merge also trigger a select (i suppose it will to get the attached instance) whereas hibernate update won't ?

please don't try to explain me things that can already be found here What are the differences between the different saving methods in Hibernate?

Community
  • 1
  • 1
Gab
  • 7,869
  • 4
  • 37
  • 68
  • I think you cannot tell generally that a JPA merge will trigger select: it depends on how the entity looks like, e.g whether it has a `@Version` field or whether the ID is generated by your code. – V G Mar 17 '14 at 16:28
  • the spec seems indeed to say that : Any Version columns used by the entity must be checked by the persistence runtime implementation during the merge operation and/or at flush or commit time. In the absence of Version columns there is no additional version checking done by the persistence provider runtime during the merge operation. – Gab Mar 17 '14 at 16:36
  • so the returned attached instance is just an attached clone of the given one and is never retrieved from database ? – Gab Mar 17 '14 at 16:38
  • As I understood the spec, JPA does not force any implementation to fetch the updated row. Now about hibernate: I am not a member of Hibernate's team and cannot answer that question, but you could browse the code (for more versions) to check that. Besides, I checked a simple `merge()` and it seems indeed not to make an additional select (which makes sens when you think of performance). – V G Mar 17 '14 at 16:56
  • Alter logging level & observe logs, you should get answer in it. – Nayan Wadekar Apr 14 '14 at 08:23

0 Answers0