I have these 2 classes:
@Entity
public abstract class Compound {
@OneToMany(fetch = FetchType.EAGER, mappedBy="compound",
targetEntity=Containable.class, cascade = CascadeType.ALL)
private Set<Containable> containables = new HashSet<>();
}
@Entity
public abstract class Containable {
@ManyToOne(optional=true, fetch = FetchType.EAGER, cascade = CascadeType.ALL)
private Compound compound;
}
What I want to achieve in a type-safe manner is that a specific implementation of Compound only accepts a specific implementation of Containable and vice versa.
How can I achieve this?
EDIT:
I already had the solution from asenovm, just wanted to double-check it is actually the correct one.
My follow-up question is, if I have class Compound<T extends Containable> and class Containable<T extends Compound> Containable and Compound are raw types or do I get that wrong? Because in class Compound<T extends Containable> T is actually a Containable and not anything else.
Something like this perhaps?