I am facing problem with hibernate\'s explicit polymorphism. I used the polymorphism annotation and set it to explicit, but with get() and collections in mapped classes i al
If you look at the definition of PolymorphismType.EXPLICIT it says:
EXPLICIT: This entity is retrieved only if explicitly asked.
To hide the subclasses, you will have to annotate the subclasses with EXPLICIT and not the base class.
Its a common miss understanding, I too had the same doubt once..
This is what really Happens in explicit polymorphism .
polymorphism explicit only applies on root entities and prevent queries naming a (unmapped) superclass to return mapped sub entities
In your case, if Entity Class Nodes were not mapped and Persons were having polymorphism explicit, then Nodes would not return Persons elements.
Look at this code..
@Entity
@Table(name="Nodes")
@Inheritance(strategy = InheritanceType.JOINED)
public class Node implements Serializable {
...
}
@Entity
@Polymorphism(type= PolymorphismType.EXPLICIT)
@Table(name="Persons")
public class Person extends Node {
}
@Entity
@Polymorphism(type= PolymorphismType.EXPLICIT)
@Table(name="Networks")
public class Network extends Node {
}
Its basically the reverse of what everyone have in there mind.!!