Expert |
|
Joined: Tue Sep 16, 2003 4:06 pm Posts: 318 Location: St. Petersburg, Russia
|
Imagine you have Company (COMPANY table) and Employee (EMPLOYEE). Each Employee may work for several companies simultaneously so you create many-to-many mapping using COMPANY_EMPLOYEE table with two columns (COMPANY_ID, EMPLOYEE_ID)
Company has <set> named "employees" which contains all its employees. What happens when you load company and remove one of the items (Employees) from this set? Hibernate will remove association between particular Employee and particular Company - in fact, single record is removed from EOMPANY_EMPLOYEE table. Employee with given ID still exists in the EMPLOYEE table - it can be loaded and used the way you want.
But if you use all-delete-orphan cascading, Hibernate will also remove corresponding record from EMPLOYEE table effectively erasing that Employee.
all-delete-orphan is used when child objects can not exist without parent.
|
|