java hibernate: selecting the discriminator column in polymorphic hql query java hibernate: selecting the discriminator column in polymorphic hql query sql sql

java hibernate: selecting the discriminator column in polymorphic hql query


You can do it as follows:

select a.class, a.id, a.name, a.age from Animal a

From Hibernate Documentation:

The special property class accesses the discriminator value of an instance in the case of polymorphic persistence.


Hibernate query objects, does not know columns. So unless you have a property named discriminator in your Animal object you cant do that. You can do the query in sql or get the entire object and then to get the inherited type, for that you can use "instanceof"