Code:
public abstract class Building {
@Id
Long resourceId;
@ManyToMany(cascade = { CascadeType.ALL })
private List<Project> projectList;
}
@Entity
public class Office extends Building {}
@Entity
public class House extends Building {}
@Entity
public class Project {
@Id
Long id;
@ManyToMany(cascade = { CascadeType.ALL })
private List<Building> buildingList; // here is my problem!!!!!
}
My question is, how do I implement a bidirectional many-to-may relationship between Project and Building? I want to avoid duplicating the relationship from Project to House and from Project to Building. Therefore I want the many to many relation from Project to Building. And I want to create a Project, add an Office to it and save it (entityManager.persist(project)).
I am a dead man by now tried a lot of options, @CollectionOfElements on buildingList ,InheritanceType.SINGLE_TABLE on Building. It all did not work.
Anyone knows which annotations I have to add in order to make this work?