From version 5.4.11.Final, more SQL queries than usual are generated under certain conditions, please see the little project I made to try to understand : https://gitlab.com/julien.leloup/spring-data-jpa-doc
This project is a Spring Data JPA project and uses :
H2 database (on a PostgreSQL database the problem is the same)
In this project there are 5 entities with the following relations :
A ----- C (1-N)
B ----- C (1-N)
C ----- D (1-N)
D ----- E (N-1)
All the relations are bi-directionnal and use a FetchType LAZY
On Hibernate-core 5.4.10.Final and prior, if I execute the following query :
it produces only 1 SQL request, which is correct if I understood correctly Spring Data JPA :
But From Hibernate-core version 5.4.11.Final, the same code produces 3 requests :
Could you please investigate ?
Note : first I opened the following ticket to Spring Data JPA team :
Their conclusion is "Until demonstrated otherwise, I'll have to assume this is caused by Hibernate."
It seems a new bug exposed by your reporting. Thanks.
If you wanted to maintain the status quo, you can switch from FETCH graph mode to LOAD mode and I am sure only the first SQL would be generated.
You are welcome. Thanks to you !
Created a PR with a test case
PR created at: . Thanks for Andrea’s testing code. Good bug reporting!
Many thanks all, this is fixed now and will be included in 5.4.19 (and 5.5+)