-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Relationship inconsistency?
PostPosted: Fri Apr 20, 2007 12:00 pm 
Senior
Senior

Joined: Mon Jul 24, 2006 8:43 am
Posts: 160
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.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 23, 2007 10:15 am 
Red Hat Associate
Red Hat Associate

Joined: Mon Aug 16, 2004 11:14 am
Posts: 253
Location: Raleigh, NC
Have you tried setting cascade="all-delete-orphan" on the collection mapping?

http://www.hibernate.org/hib_docs/v3/re ... d-cascades

-Chris


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.