After migration from Hibernate 5.6 to 6.2 (also checked on 6.6), we faced the performance degradation in our application.
After enabling SQL logs (we tested on MySQL) we have seen a lot of queries that we don’t have in Hibernate 5th version.
Especially, on EntityManager.refresh(entity), we have got a big difference.
E,g, for the Orders in the Hibernate 5.6 we have 4 queries, but in Hibernate 6.2 we have 30 queries. (also checked on 6.6.x)
All these extra queries were for @OneToMany collections with FetchType.LAZY.
I was thinking that max_fetch_depth property may help, but it did not.
Is this expected behavior for 6.x version?
Could we come back in 6.x to 5.x behavior for EntityManager.refresh(entity)?
Starting with Hibernate 6.0, the laziness of such associations is properly respected
But in our case the laziness of the associations is NOT respected.
I checked all the migrations guides (6.0, 6.1, 6.2) and I have not found anything about fetch type Eager/Lazy or something related to the @OneToMany annotation.
I guess this ties into the fact that EntityManager.refresh() will now try to refresh the whole graph reachable through CascadeType.REFRESH or implicitly also CascadeType.ALL, but it’s hard to say for sure without seeing the code.
Please try to create a reproducer with our test case template and if you are able to reproduce the issue, create a bug ticket in our issue tracker and attach that reproducer.