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.  [ 6 posts ] 
Author Message
 Post subject: help needed : NonUniqueObjectException
PostPosted: Tue Jan 30, 2007 3:44 am 
Newbie

Joined: Mon Jan 29, 2007 7:29 am
Posts: 6
i have a one-to-many mapping and when i m trying to add the object to the list in the parent object i m getting the following error

please help me out with this
what could be the possible reason for the same


Last edited by Sameer11sep on Mon Apr 09, 2007 8:06 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 30, 2007 9:12 am 
Beginner
Beginner

Joined: Thu Sep 22, 2005 10:48 am
Posts: 30
Location: Rio de Janeiro, Brazil
You implement equals and hashcode?

_________________
Please don't forget to rateME!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 31, 2007 12:43 am 
Newbie

Joined: Mon Jan 29, 2007 7:29 am
Posts: 6
The problem was that i was removing all the child objects from the list in the parent and then inserting so in the same session it was not able to commit the delete and was throwing this error.

i actually did a workaround ...implemented the equals and hashcode methods and updated those child objects that are present already with the same composite identifier in the list and if not found i inserted the object.

can u suggest me a better way to do this ??


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 31, 2007 12:53 am 
Expert
Expert

Joined: Tue Jan 30, 2007 12:45 am
Posts: 283
Location: India
Instead of save or update use merge.

_________________
Dharmendra Pandey


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 01, 2007 1:41 am 
Newbie

Joined: Mon Jan 29, 2007 7:29 am
Posts: 6
thanks for the reply
could u please send me an example of merge


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 01, 2007 1:58 am 
Expert
Expert

Joined: Tue Jan 30, 2007 12:45 am
Posts: 283
Location: India
Hi Sameer11sep,

pass employeeGroup which contain collection of employee (with out ID)

then in method select employeeGroup from DB by employeeGroup.ID
in employeeGroupDB .And do like this.

if (employeeGroupDB == null) {
session.saveOrUpdate(employeeGroup);
} else {
session.merge(employeeGroup);
}
session.flush();
session.clear();

_________________
Dharmendra Pandey


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.