Error in Inheritance Mapping with @ManyToOne relations in concrete classes

Description

Given an abstract class with single table inheritance

and some concrete implementations

and another entity that joins those comments polymorphic

a query on activities fails with an entity not found exception. Hibernate 4.3.x inner joins the first commendable (From BulletinComment) in a query that ends in " where comment0_.id=32782 and comment0_.commentable_type in ('News', 'Page')" " but the given id is a PageComment.

The example works in Hibernate 4.2.x. It also works in Hibernate 4.3 if i remove the optional flag in the ManyToOne relations but to me, those associations are not optional and i see no reason to remove it.

And ideas or arguments why i should made them optional with hibernate 4.3? This actually not my only example.

Thanks for looking!

Attachments

2

Activity

Show:

Michael Simons December 9, 2015 at 8:02 PM

Yeah, i see, that is indeed true.

And as i cannot really argue for my case from a database design point of view, you're right. My old schema is indeed flawed. Schema is about 10 years old, there should be a foreign key which is also not possible… For the same reason Hibernate "fails" me.

Thanks for looking at this. If you want, close it, it's my problem, not yours.

Andrea Boriero November 20, 2015 at 5:31 PM
Edited

Hi

a problem I see in your mapping is the same name used for the @JoinColum

in 2 classes

and

belonging to SINGLE_TABLE inheritance and referring to 2 different Entities.

creates

and

creates

The same column is used for 2 differents FKs and this is not possible.
So your problem can be solved assigning 2 different names for the @JoinColumn.

The issue instead remains when no name is assigned to the 2 @JoinComun.

Michael Simons October 30, 2015 at 5:19 PM

I've added test cases with your templates for Hibernate 4 as well as 5.

They include a H2 database, as Hibernate creates wrong foreign keys here as well (which isnt a problem for me, as it is a legacy scheme, but anyway).

In Hibernate 4.3.0 the following wrong query is generated:

4.3.11 and 5 generate this:

The problem in both: The join onto that commentable thing is wrong. It targets the wrong table, either outer or inner.

Thanks.

Steve Ebersole October 28, 2015 at 3:24 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:17 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/

Rejected

Details

Assignee

Reporter

Labels

Components

Priority

Created January 30, 2014 at 8:58 PM
Updated January 10, 2017 at 12:24 PM
Resolved February 17, 2016 at 2:05 AM