Hibernate 4 explicit polymorphism (abstract) not working?

I ran into a problem with explicit sleep polymorphism. I used the polymorphism annotation and set it explicitly, but with get () and collections in the mapped classes, I always get all the subclasses. I see all subclasses with left join in hibernate "show_sql" output. What is the problem? Am I misunderstanding the documentation? Or is this a bug in sleep mode 4? I have not seen a single example with hibernation 4 and annotation of polymorphism.

sessionFactory.getCurrentSession().get(Node.class, 111); // return subclasses! @Entity @Table(name="Nodes") @Inheritance(strategy = InheritanceType.JOINED) @Polymorphism(type= PolymorphismType.EXPLICIT) public class Node implements Serializable { ... } @Entity @Table(name="Persons") public class Person extends Node { } @Entity @Table(name="Networks") public class Network extends Node { } ...and other subclasses... 
+8
polymorphism annotations hibernate
source share
2 answers

His general understanding of misses, I also had the same doubt once ..

This is what really happens in explicit polymorphism.

Polymorphism explicitly applies only to root objects and prevents queries that name (unmapped) superclasses to return mapped sub entities

In your case, if Entity Class Nodes were not displayed and Persons were with a pronounced polymorphism, then Nodes will not return people Elements .

Take a 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 { } 

This is basically the opposite of what everyone has in mind. !!

+4
source share

If you look at the definition of PolymorphismType.EXPLICIT , it says:

EXPLICIT: This object is retrieved only when explicitly requested.

To hide subclasses, you will need to annotate subclasses with EXPLICIT, not the base class.

+1
source share

All Articles