N@ruto wrote:
I know about the existence of polymorphis tag and annotation but i understand, throw other topic, that this doesn't work in the actual versione of hibernate.
I am not aware of a bug, and for sure no one gave me a reproducible test case for it.
For you case, it is not supported in Hibernate because it is not supported in Java. If you have an instance of class B (subclass of A), there is no way (and no need) to convert it into an instance of A only, it is by essense an instance of class B.
What polymorphism=explicit does is
B subclass of A and B polymorphism explicit and B the root entity (not a subclass),
Then from A will not return Bs
More formally
Quote:
Implicit polymorphism means that instances of the class will be returned by a query that names any superclass or implemented interface or the class and that instances of any subclass of the class will be returned by a query that names the class itself. Explicit polymorphism means that class instances will be returned only by queries that explicitly name that class and that queries that name the class will return only instances of subclasses mapped inside this <class> declaration as a <subclass> or <joined-subclass>. For most purposes the default, polymorphism="implicit", is appropriate. Explicit polymorphism is useful when two different classes are mapped to the same table (this allows a "lightweight" class that contains a subset of the table columns).