I have the following classes:
Code:
@javax.persistence.Entity
@Entity(polymorphism = PolymorphismType.EXPLICIT)
@Table(name = "A")
@Inheritance(strategy = InheritanceType.JOINED)
public class A {
@ManyToOne
@JoinColumn(name = "container_id")
private Container container;
}
@Entity
@Table(name = "B")
public class B extends A
I get the expected polymorphic behavior when I load these types directly. That is, if I load all entities of type A, then I only get type A, or if I load all entities of type B, then I only get type B.
If I have an association collection of type A in another entity, then I do not get the polymorphic behavior that I would expect. That is, if I have the following class defined:
Code:
@Entity
public class Container {
@OneToMany(fetch = FetchType.LAZY, mappedBy = "A", targetEntity = A.class)
private List<A> a;
}
If I load a class of type Container, then its associated collection of A contains entities of type A and type B whereas I expect only A. Can anyone tell me how I have misconfigured my entities to get the behavior I am seeing rather than what I am expecting?
Thanks in advance,
-Anthony