| When selecting data from tables that use InheritanceType.JOINED, Hibernate does not always choose the correct type for the returned entities. The attached test case always returns the same type for all found entities, when three different types should be returned. It only happens on Oracle12c, if a certain amount of child table definitions exist and a certain set of IDs are queried. Everything works well on Oracle11g. While this might be an Oracle bug, there exist a SQL that would return the correct entity types:
with q as (
select
account0_.id as id1_0_,
account0_1_.id as id1_1_,
account0_2_.id as id1_2_,
account0_3_.id as id1_3_,
account0_1_.creditLimit as creditLimit1_1_,
case
when account0_1_.id is not null then 1
when account0_2_.id is not null then 2
when account0_3_.id is not null then 3
when account0_.id is not null then 0
end as clazz_org
from Account account0_
left outer join CreditAccount account0_1_ on account0_.id=account0_1_.id
left outer join DebitAccount account0_2_ on account0_.id=account0_2_.id
left outer join SpecialAccount account0_3_ on account0_.id=account0_3_.id
where account0_.id in (1 , 3 , 4)
)
select q.*,
RANK() OVER (ORDER BY id1_0_) clazz
from q
;
|