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:
select
activity0_.id as id1_0_0_,
activity0_.reference_object_id as referenc2_0_0_,
comment1_.id as id2_1_1_,
comment1_.name as name3_1_1_,
comment1_.text as text4_1_1_,
comment1_.commentable_id as commenta5_1_1_,
comment1_.commentable_type as commenta1_1_1_,
page2_.id as id1_3_2_,
page2_.name as name2_3_2_
from
activities activity0_
inner join
comments comment1_
on activity0_.reference_object_id=comment1_.id
inner join
pages page2_ -- This join is wrong!
on comment1_.commentable_id=page2_.id
where
activity0_.id=?
4.3.11 and 5 generate this:
select
activity0_.id as id1_0_0_,
activity0_.reference_object_id as referenc2_0_0_,
comment1_.id as id2_1_1_,
comment1_.name as name3_1_1_,
comment1_.text as text4_1_1_,
comment1_.commentable_id as commenta5_1_1_,
comment1_.commentable_type as commenta1_1_1_,
page2_.id as id1_3_2_,
page2_.name as name2_3_2_
from
activities activity0_
inner join
comments comment1_
on activity0_.reference_object_id=comment1_.id
left outer join
pages page2_
on comment1_.commentable_id=page2_.id
where
activity0_.id=?
The problem in both: The join onto that commentable thing is wrong. It targets the wrong table, either outer or inner.
Thanks.
|