The problem:
Querying on a property of a subclass of a polymorphic association does not work. The resulting SQL query refers to an alias that does not exist,
causing a "unknown column" SQL exception.
This is similar to the following posting except in my case it is a many-to-one association.
http://forum.hibernate.org/viewtopic.ph ... highlight=
There was no proper response for that topic.
Let me try to lay it down in simple terms.
The Entities/Mappings:
Mapping for A
Class A
property superClassProperty
Joined SubClass B extends A
property subClassProperty
End of Mapping A
Mapping for R
Class R
property id
property refToA of type A (many-to-one) polymorphic association
property someOtherProperty
End of Mapping R
The Query:
from R as r1 where r1.id = 'someid' order by r1.refToA.subClassProperty
The above query results in the SQL exception I mentioned earlier however the following query works perfectly.
from R as r1 where r1.id = 'someid' order by r1.refToA.superClassProperty
The difference being that the latter refers to a property of A rather than a subclass' property.
What I really want to know is how can I achieve the main goal of querying on a subclass property of a polymorphic association.
Thanks in advance for any help on this.