I have the following
@MappedSuperclass
public abstract class A {
@Id @GeneratedValue
public Long id;
}
@Entity
public class B extends A {
}
@Entity
public class C extends A {
}
@Entity
public class D {
@ManyToOne
public A a;
}
The problem is class D and the field a (could be either of type B or C). What should be the mapping?
If you reference an
Afrom another entity, thenAshould not be a MappedSuperclass, but an entity. You should annotate it with@Entity, and choose an inheritance strategy.Other than that, the mapping will stay as is.