Criteria select with multi level inheritance using discriminator column referencing wrong table

Description

Having multiple level inheritance using @DiscriminatorColumn and @DiscriminatorValue, hibernate only references the correct table for the discriminator column when querying for leaf classes. Example:

Class A with discriminator column "dc"
Class B extends A
Class C extends A
Class D extends B

When querying for class C and D it will correctly use A.dc in both queries. When querying for class B (from which D derives) it will use B.dc in the query, instead of A.dc. This leads to the database complaining that there is no "dc" column in table B.

Example query is attached, including stacktrace'd error.

Attachments

1

Activity

Show:

Christian Beikov January 21, 2025 at 5:54 PM

No test or response provided, so closing.

Chris Cranford April 14, 2016 at 2:03 AM

/ ,

Based on the information provided, I used the existing discriminator test suite in hibernate-core, org.hibernate.test.discriminator, since the inheritance example mimics this issue perfectly. I made sure the mapping file used the PartTimeEmployee entity class, which was commented out and added the following test case.

Your A entity is Person, B is Employee, C is Customer, and D is PartTimeEmployee.

Simple Inheritance Test Case

Based on the above, I cannot reproduce this in either branch 5.0 or 5.1. , since you said you could reproduce this in ORM5, can you confirm whether you were attempting to query the hierarchy the same way as I did?

Ihor Herasymenko January 4, 2016 at 9:47 PM

Confirmed. Affects Hibernate 5.

Steve Ebersole October 28, 2015 at 3:25 AM

As part of verifying that this issue affects 5.0, please just set the "Affects version". Leave the "verify-affects-5.0" label and leave the issue in "Awaiting Response" status; these are critical for us to be able to track these verifications and triage them. Thanks.

Steve Ebersole October 27, 2015 at 7:15 PM

This bug report does not indicate that the reported issue affects version 5.x. Versions prior to 5.x are no longer maintained. It would be a great help to the Hibernate team and community for someone to verify that the reported issue still affects version 5.x. If so, please add the 5.x version that you verified with to the list of affected-versions and attach the (preferably SSCCE) test case you used to do the verification to the report; from there the issues will be looked at during our triage meetings.

For details, see http://in.relation.to/2015/10/27/great-jira-cleanup-2015/

Cannot Reproduce

Details

Assignee

Reporter

Labels

Components

Affects versions

Priority

Created August 4, 2014 at 4:25 PM
Updated January 21, 2025 at 5:54 PM
Resolved January 21, 2025 at 5:54 PM