I have a 1:M relationship in my model between Company and Employees.
The company has an setEmployees(List list) and a getEmployees() API.
The company has 3 specific employess called aEmployee, bEmployee, cEmployee and everything is persisted.
Now there is another list of employees, list2 which contains two employees: yEmployee, zEmployee.
I do:
Code:
company.setEmployees(list2);
yEmployee.setCompany(company);
zEmployee.setCompany(company);
When I do, company.getEmployees(), a list of size 2 is returned, containing Y, Z which is ok. This makes sense.
However when I commit this update, and do a refresh on company and than to
company.getEmployees(), a list of 5 employees is returned containing A,B,C,Y, Z is returned.
i.e. the relationships to A, B, C are not deleted. Fair enough, but why does hibernate give the impression that they are or will be after the setEmployees(list2) is invoked.