One child entity has an OneToMany relationship to a certain entity of type A using FetchMode.SUBSELECT
Another child entity has another OneToMany relationship to a certain entity of type B also using FetchMode.SUBSELECT
When
Querying both entities and initializing the first child relationship
Then
A NPE happens when hibernate wrongly tries to load the 2nd child relationship with entity of type A, which mapping doesn’t exist for the second child type.
The issue happens because SubselectFetch.StandardRegistrationHandler.addKey method wrongly registers a key even for the child entity which doesn’t have that collection mapped.
This works fine on latest hibernate 5 series. It doesn’t work in any hibernate 6 series.
Failing test scenario attached and also available here
Given:
Single table inheritance using discriminator
One child entity has an OneToMany relationship to a certain entity of type A using FetchMode.SUBSELECT
Another child entity has another OneToMany relationship to a certain entity of type B also using FetchMode.SUBSELECT
When
Querying both entities and initializing the first child relationship
Then
A NPE happens when hibernate wrongly tries to load the 2nd child relationship with entity of type A, which mapping doesn’t exist for the second child type.
The issue happens because SubselectFetch.StandardRegistrationHandler.addKey method wrongly registers a key even for the child entity which doesn’t have that collection mapped.
This works fine on latest hibernate 5 series. It doesn’t work in any hibernate 6 series.
Failing test scenario attached and also available here