Useless queries after migrating to Hibernate 6

196 Views Asked by At

I tried to migrate a spring boot project to the newest version. Which included an upgrade to hibernate 6. I have done that before and never had an issue like this. I use spring-data-jpa Repositories with an MSSQL Database. After the Update close to all of my queries are broken. I debugged into it and found out, the JPQL looks fine. But somewhere on the way to TransactSQL something mysterious is happening. I'd like to show you three of the problems I faced.

Problem Nr. 1

@Entity public class Gender {
    ...
}

@Entity public class Person {
    @ManyToOne public Gender gender;
    @Embedded public Details details;
}

With something as simple as this. I expected to see select ... from Person or maybe even select ... from Person p left join Gender g on ... if Gender is fetched eagerly. But what i got was

select ... from Person p1 left join Person p2 on p1.id = p2.id left join Gender g on ...

which works but it is rather useless to have that second join on Person.

Problem Nr. 2

resultPerson.details is null although the query actually returned values for the columns inside Person.details.

Problem Nr. 3

A more complex query I wrote myself now joins stuff in the wrong order:

select Person p1
left join Something s1 on s2.somethingId = s1.somethingId
left join SomethingElse s2 on ...

Question

All these queries worked fine before the upgrade and haven't been touched during the upgrade. All the errors are so diverse, that I don't even know where to start looking. I don't expect you to solve my problems. I'm just asking for hints. Hope anybody has seen this before.

0

There are 0 best solutions below