I have the following 3 entities:
- entity class A implements interface X
- entity class B implements interface X
- entity class C
Where I could like entity class C to be able to hold a reference to an entity of type X, that is: either A or B.
Is it possible to do this without having two reference fields in C, like:
@ManyToOne private C parent;
Or do I need to have one reference for each implementation of C and do the assignment myself?
Nope. JPA doesn’t define persistence for fields/properties of interface types. JDO is the only persistence specification to allow that.
Only thing you could do is have a common base class, but that may be impossible with your model.