bungrudi
bungrudi

Reputation: 1417

Casting to specific class in HQL

My situation is like this.. (note: for those who work with JBPM might already familiar with following data structures and HB mapping)

Class LongInstance extends from VariableInstance, with the mapping for field "value" overridden in LongInstance. The mapping for VariableInstance is here and for LongInstance here.

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

The question: how can I query the polymorphic collection using specific/overridden property of the 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)"

Upvotes: 4

Views: 1620

Answers (2)

ssedano
ssedano

Reputation: 8432

HQL supports the runtime discriminator:

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

Upvotes: 1

Guillaume
Guillaume

Reputation: 14656

Why not:

.. from TokenVariableMaps tvm, LongInstance li 
where tvm.variableInstances = li 
and ...

Upvotes: 1

Related Questions