Hi,
I use hibernate 3.3.0ga.
Let's say we have a simple Person Entity which could have several employers and severals employees. There would be an ManyToMany association like :
Code:
@Entity
public class Person {
...
@ManyToMany
@JoinTable(name = "employers_employees")
public List<Person> getEmployees() {
return employees;
}
@ManyToMany(mappedBy = "employees")
public List<Person> getEmployers(){
return employers;
}
In the database, a special join table, "employers_employees", will be created with 2 columns, say :
- employee_id
- employer_id
If I delete a Person , how can I cascade my relationship @ManyToMany to delete only the related entries in the join table "employers_employees" but not the associated persons (employers and employees)
As far as I tested, this is not the default behaviour : when I try to delete a Person, hibernate says it will be resaved by cascade because some other object contains it in its collection.
Is there a way to map ManyToMany collections for me not to care about those problems ?
Thanks