Hibernate version:
2.1.7
Is there an efficient way in HQL to determine the class of a polymorphic mapped object, given the id, without loading the whole object?
for instance, lets say you have this hierarchy:
Code:
<class name="A">
<id name="id".../>
<joined-subclass name="B">
<key column="id"/>
</joined-subclass>
<joined-subclass name="B">
<key column="id"/>
</joined-subclass>
</class>
can you get the class type of object id'd by "someID" without doing
Code:
Class clazz = session.load(A.class, "someID").class;
and without resorting to an ugly raw sql statement like:
Code:
select case
when c.id is not null then 'C'
when b.id is not null then 'B'
when a.id is not null then 'A'
as clazz
from A a
left outer join B b on a.id = b.id
left outer join C c on a.id = c.id
where a.id = "someID"