I have a question regarding how the new TREAT downcasting is handled.
Currently we have the following models using JOINED inheritance.
AbstractBase { String value0; } Child0 extends AbstractBase { String value1; } Child1 extends AbstractBase { String value2; }
Now using the Criteria API (cb.treat(Root<X>, Class<T>)) we generate the following HQL:
select generatedAlias0.id, generatedAlias0.value0, treat(generatedAlias0 as Child0).value1 from AbstractBase as generatedAlias0
Now this gets translated to SQL as follows:
select abstractba0_.id as col_0_0_, abstractba0_.VALUE_0 as col_3_0_, abstractba0_1_.VALUE_1 as col_4_0_ from PCY_T_ABSTRACT_BASE abstractba0_ inner join PCY_T_CHILD_0 abstractba0_1_ on abstractba0_.id=abstractba0_1_.id left outer join PCY_T_CHILD_1 abstractba0_2_ on abstractba0_.id=abstractba0_2_.id
For a JOINED-Inheritance setup it would seem that a LEFT JOIN is more appropriate here instead of the INNER JOIN used to pull in the CHILD_0 table.
Now my question is, is there anyway to force the joining of CHILD_0 to use a LEFT OUTER JOIN? From the JPA 2.1 API there appears to be no possibility of passing in a JoinedType value, but perhaps, there is a Hibernate-specific method which could be used instead?
Thanks, Tito
|