I have a many to may relationship CohortGroup and Employee. Any time I insert an Employee into the CohortGroup hibernate deletes the group from the resolution table and ins
I have inserts acting the way I expect them to now. Thanks to Pascal and z5h, I have learned a lot. I believe I have the hashCode and equals implemented correctly. This never solved the problem for me though. Instead I have implemented an Intermediate Entity.
For what it is worth below are the mapping in my Employee, CohortGroup, and now CohortGroupMemeber classes.
Employee:
@OneToMany(mappedBy="member")
public List getMemberGroups(){
return memberGroups;
}
public void setMemberGroups(List grps){
memberGroups = grps;
}
CohortGroupMember
@ManyToOne
@JoinColumn(name="USERID")
public Employee getMember(){
return emp;
}
public void setMember(Employee e){
emp = e;
}
@ManyToOne
@JoinColumn(name="COHORT_GROUPID")
public CohortGroup getGroup(){
return group;
}
public void setGroup(CohortGroup cg){
group = cg;
}
CohortGroup
@OneToMany(mappedBy="group")
public List getMembers(){
return members;
}
public void setMembers(List emps){
members = emps;
}
The book I followed for this is Java Persistence with Hibernate chapter 7.2.3