After migrating from hibernate 5.6.15 (Spring boot 2) to hibernate 6.6.25 (Spring boot 3) I have a degradation of performance in the application here are the metrics between the two versions when I do a saveAll(entities):
This report is not really useful. Clearly your new application version takes a lot of time to acquire JDBC connection and also processes way more data, so clearly, there will be a difference in execution time.
If you want help, you will have to analyze this situation yourself a bit further and ask more targeted questions.
Thank you for your reply. I ran the same scenario and had the same amount of data to save (entities).
total ShiftNameEntity : 123
total VariantEntity : 0
total ShiftPartEntity : 293
total ServiceCounterEntity : 0
Here’s my code:
serviceEntityDao.saveAll(services);
I used a for loop to see the number of queries executed for each entity. I noticed that with Hibernate version 6, it executes more queries than with version 5.
I don’t know what this saveAll method does. Please, this is a Hibernate ORM forum, so reduce the code to the Hibernate ORM primitives like EntityManager#persist/EntityManager#merge.
The multiple queries were triggered because I declared the @OneToManyOneToMany relationship in SecondEntity.
What I don’t understand is why Hibernate 5 didn’t report this issue, but with Hibernate 6, it triggers additional queries.
After remo@OneToManying the @OneToMany relationship in SecondEntity, I no longer experienced any performance issues and the number of queries executed significantly decreased.
I have no idea what you think you’re doing, but removing @OneToMany is probably not a solution. I suppose that your or the Spring code uses EntityManager#merge under the hood, which will trigger joining of of associations that are CascadeType.MERGE or CascadeType.ALL to get the initial state for that merge call via a select statement.
If you’re trying to insert data, consider using EntityManager#persist. If you are in fact updating existing data, you have two options. If you can change the CascadeType, then do that. Otherwise, try loading the existing data manually first and apply the changes to these objects directly instead of using EntityManager#merge. That way, you control what data is loaded explicitly and only the relevant data is flushed.