Posts

Showing posts from August, 2021

Hibernate Traps: Merge versus Update

 Introduction Welcome to another installment of Hibernate Traps. This time we will take a closer look at one of the most basic and commonly used features - updating Database state with a detached Entity. This time the title is also kinda stretched, because this Trap belongs more to the general JPA realm, than to Hibernate. However because Hibernate is the most commonly used implementation of JPA, and I'm not entirely sure whether all implementations of JPA behave the same way as Hibernate in regard to merging , I will again carry on with the title as it is. What JPA is not telling You... Merging a detached Entity is one of the most common operations in any Database-driven application. Any time we get a REST Request that updates data in our application, it is very likely we will use merge operation and expect Hibernate to generate one or more Update SQL statements. This may not be the case if we need to find Entities using some search criteria prior to updating them, because then we