Casting for a specific class in HQL

My situation is similar to this (note: for those who work with JBPM, you may already be familiar with the following data structures and HB mapping)

The LongInstance class extends from VariableInstance, with a mapping for the value of a field overridden in LongInstance. The mapping for VariableInstance is here and for LongInstance is here .

VariableInstance is mapped polymorphically to the collection in TokenVariableMap, mapping here .

Question: how can I query a polymorphic collection using a specific / overridden property of a member class?

I'm looking for something like this "... from TokenVariableMaps tvm left join fetch tvm.variableInstances tvi where cast (tvi as LongInstance) .value in (: vars)"

+4
source share
2 answers

Why not:

.. from TokenVariableMaps tvm, LongInstance li where tvm.variableInstances = li and ... 
+1
source

HQL supports the runtime discriminator:

select c from AnyClass where c.class = com.pack.SubClass

+1
source

Source: https://habr.com/ru/post/1335026/


All Articles