NPE with SubselectFetch and inheritance

Description

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

Attachments

1

Activity

Show:
Fixed

Details

Assignee

Reporter

Worked in

Components

Fix versions

Affects versions

Priority

Created March 7, 2023 at 7:42 AM
Updated March 17, 2023 at 8:19 PM
Resolved March 8, 2023 at 2:32 PM