Hi, All. We recently upgraded an application from SpringBoot 2.5 (Hibernate ORM core version 5.4.33) to SpringBoot (Hibernate ORM core version 6.5.2.Final) and noticed a change in one of our processes. Our configuration is pretty simple: Oracle DB backend and just configured the data source and everything kept at default.
Our process writes 2 sets of objects to 2 tables using JpaRepository and a 3rd set using EntityManager and native SQL queries. In both versions of Hibernate, for the first 2 tables, when saveAll()
is executed, we can observe Hibernate preparing for the actual commit by doing a bunch of SELECTs on the sequence generators for the ID. Then when the 3rd set of objects are committed one by one with a forEach
call to an EntityManager backed DAO, the data for the first 2 tables get INSERTed.
The difference though is that in the older version of Hibernate, data for the first 2 tables are INSERTed on the first save to the third table using EntityManager and that’s it. No more queries are done against the first 2 tables. However, in the newer version of Hibernate, it does the INSERTs to the first 2 table with the first write to the 3rd via EntityManager, but performs an UPDATE seemingly for all the objects of the first 2 tables with every succeeding INSERT to the 3rd.
Could someon explain what is happening here? More importantly, how do we avoid the superfluous UPDATEs to the first 2 tables that is happening?