Left outer joins do not work with polymorphic entities due to use of discriminator in the main query condition

Description

Given

  • A simple entity

  • A polymorphic entity

When

  • querying the simple entity doing a left join with the polymorphic entity

Then

  • The results will always be empty when the left joined entity is not present

 

 

In hibernate 5.6.15, this example just works, because hibernate 5 completely ignores the discriminator when generating the SQL (might be a limitation or a bug), but the expected outcome for the example is kept and we get the expected result which is the single list with the entity b in it:

 

In hibernate 6.2.0, the resulting list will always be empty, because hibernate 6 does not ignore the discriminator, but adds it to the main query criteria (this part is the wrong part). Since this is a left join, the joined entity is optional and adding the discriminator criteria to the main part of the query will result to empty when the joined entity is not present.

 

A failing test scenario is attached and also available here

Attachments

1

Activity

Show:
Fixed

Details

Assignee

Reporter

Worked in

Fix versions

Affects versions

Priority

Created April 5, 2023 at 9:13 AM
Updated May 8, 2023 at 12:37 PM
Resolved April 19, 2023 at 9:53 PM