Versions 5.4.11.Final+ produce too many sql queries

Description

Hi,

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 :

  • spring-boot-starter-parent 2.2.4-RELEASE

  • H2 database (on a PostgreSQL database the problem is the same)

  • Hibernate-core 5.4.12.Final

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 :
https://jira.spring.io/browse/DATAJPA-1747
Their conclusion is "Until demonstrated otherwise, I'll have to assume this is caused by Hibernate."

Regards

Environment

None

Activity

Show:
Nathan Xu
July 3, 2020, 6:31 PM
Edited

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.

Julien Leloup
July 3, 2020, 9:12 PM

You are welcome. Thanks to you !

Andrea Boriero
July 4, 2020, 9:29 AM

Created a PR with a test case

Nathan Xu
July 4, 2020, 11:28 AM

PR created at: . Thanks for Andrea’s testing code. Good bug reporting!

Sanne Grinovero
July 9, 2020, 1:41 PM

Many thanks all, this is fixed now and will be included in 5.4.19 (and 5.5+)

Assignee

Nathan Xu

Reporter

Julien Leloup

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure