Fetchs used into criteria query seems to be ignored when bytecode enhancement is enabled

Description

I have an Entity A which contains a @OneToOne relation to the Entity B and Entity C. Entity B and Entity C have, in turn, a @OneToOne relation to Entity B1 and Entity C1:

I need to select all data of Entity A with some fields of Entity B and Entity C. Fields of Entity B1 and C1 have to be ignored.

Executing the query method, I’m expecting the execution of a single query,on User table, fetching right on Badge and Address tables.
But with Bytecode Enhancement enabled, three different query are executed.
It seems that hibernate ignore configured fetches into criteria query

Instead, without bytecode enhancement, a single query is righty executed:

Environment

Spring Boot 2.1.0.RELEASE with Spring Data JPA
MySql Community Server 8.0

Activity

Show:
Marcus Salles
March 1, 2019, 9:59 PM

Facing exactly the same issue with Spring Boot 2.1.3 and Hibernate 5.3.7.

Antonio Benvenuto
March 4, 2019, 10:50 AM

Marcus, regardless of this issue, I reccomend to use Projections in order to get only data you really want.

Bernd Krumböck
October 18, 2019, 7:32 AM

We have the same problem with ManyToOne. The values get fetched from database, but the lazy attributes will not be initialized (or marked as initialized). The problem at least exists in 5.4.6, 5.3.13, 5.2.17.

Assignee

Steve Ebersole

Reporter

Antonio Benvenuto

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Affects versions

Priority

Major
Configure