We have a basic JOINED inheritance setup as follows.
entity AbstractBase entity Child0 extends AbstractBase entity Child1 extends AbstractBase
We would like to query the AbstractBase and retrieve the results for all children (polymorphic query). Our HQL is as follows
select e.id, e.value0, treat(e as Child0).value0 from AbstractBase e
Now this results in the following SQL being generated.
select abstractba0_.id as col_0_0_, abstractba0_.VALUE_0 as col_1_0_, abstractba0_1_.VALUE_1 as col_2_0_ from ABSTRACT_BASE abstractba0_ inner join CHILD_0 abstractba0_1_ on abstractba0_.id=abstractba0_1_.id left outer join CHILD_1 abstractba0_2_ on abstractba0_.id=abstractba0_2_.id
The problem is the INNER JOIN on Child0. This results in only returning 1 of two records. That is, what we get back is
id
|
value0
|
value1
|
1
|
child0.value0
|
child0.value1
|
However, what we expect to get back is the following.
id
|
value0
|
value1
|
1
|
child0.value0
|
child0.value1
|
2
|
child1.value0
|
null
|
You can reproduce this behavior with the attached example.
|