I have an issue with Spring Boot 3/Hibernate 6. (Spring Boot 3.2.5)
Due to the Hibernate 6 change in how SQL queries are generated (breadth first entity walking), I am having to convert more of my mapping to FetchType.LAZY.
While doing this, I’ve noted that Hibernate is being entirely inconsistent in its fetch behavior for @OneToMany.
Some collections are being lazy loaded, and some are being EAGER fetched!
This happens on collections in the same entity, with the same configuration (example below):
@OneToMany(mappedBy = "property", cascade = CascadeType.ALL, orphanRemoval = true)
private Set<Adjustment> adjustments = new HashSet<>();
However even simpler configurations (just a mappedBy property) of the @OneToMany are having the same inconsistent result.
This is using Spring-Data-JPA with the default CrudRepository::findById().
Even applying an explicit fetch=FetchType.LAZY results the same inconsistency.
I have examined this after using IntelliJ debugging and seeing the data live immediately after the findById() call so there is no code (Jackson, etc.) causing a Lazy-fetch to occur.
I do not understand the inconsistency, and because it’s inconsistent it doesn’t appear to be something I have configured anywhere at a global level. I’m hoping I am just missing something obvious here.
Can anyone shed any light as to why this is happening>
I have tried making all my mappings exactly the same as on those associations that get lazy fetched as expected and examining for any differences in the configuration of mappings, and nothing is apparent.