Various details on how to work with persistence.
Using entity extensions in mapping
Entity extensions cannot be directly mapped. The main entity should be used instead of its extension in mapping. For example:
We have an entity of class A:
@Entity public class A { // some fields and methods }
And we have its extension of class B:
@Entity public class B { // some fields and methods @OneToOne(targetEntity = A.class) public A getA() {} }
In our particular use case we might want to map some other entity field to B:
@Entity public class UsageSample { // some fields and methods @OneToOne(targetEntity = B.class) public B getObject() {} //Wrong usage! }
The correct use case looks like:
@Entity public class UsageSample { // some fields and methods @OneToOne(targetEntity = A.class) public A getObject() {} //Correct usage. Note: you can cast the returning value B }
This behavior is due to the fact that entity extension is not a separate entity. It is just brings some additional fields to its main entity. That is why it cannot be used in relationship mapping as separate entity.