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: Session have diffrent Object same identifier value
PostPosted: Mon Apr 02, 2007 11:41 am 
Newbie

Joined: Mon Apr 02, 2007 11:36 am
Posts: 1
Location: India, Pune
Hi,

I am using following code to update SolutionCategory,
simple update without validation is working fine.....


public void update(SolutionCategory o, Errors e) throws ServiceValidationException {

SolutionCategory solutionCategory = (SolutionCategory) o;
DynamicCriteria dynaCrit = new DynamicCriteria();
dynaCrit.add("name",solutionCategory.getName(),DynamicCriteria.EQUAL);
List list = findAll(dynaCrit);

SolutionCategory tempSC = (SolutionCategory) list.get(0);
if(list.size() > 0 && !tempSC.getID().equals(o.getID()) ){
e.reject("DUPLICATE_CATEGORY_NAME");
throw new ServiceValidationException(e);
}

dao.update(solutionCategory);
}


Before updating the record I want to validate duplicate SolutionCategory Name.
So to implement that stuff I am going to fetch all record by :- List list = findAll(dynaCrit); method.

Now after this validation code while executing dao.update(solutionCategory); line my hibernate session has two different object with the same identifier value i). Original Object of the Update function
ii). another one is found by findAll method

Because of this two object, at time of saving record following error has been generate by hibernate.

a different object with the same identifier value was already associated with the session: [com..cs.solutionreg.solutioncategory.SolutionCategory#12]; nested exception is org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [com.cs.solutionreg.solutioncategory.SolutionCategory#12]

Could you give me proper solution?

i). How I detach extra Object form Hibernate Session ??
ii). Should not use this kind of validation in update function ??


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 02, 2007 11:37 pm 
Expert
Expert

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


session.merge(solutionCategory);
it would solve your problem

_________________
Dharmendra Pandey


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.