-->
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.  [ 1 post ] 
Author Message
 Post subject: Cannot update members of a collection
PostPosted: Wed Feb 02, 2005 6:42 pm 
Newbie

Joined: Wed Feb 02, 2005 6:30 pm
Posts: 2
Read the rules before posting!
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 2.1

Mapping documents:

Code between sessionFactory.openSession() and session.close():

Session sess = null;

try {

sess = PsaDAO.getHibernateSession();
Transaction t = sess.beginTransaction();



//order number is going to be based on the call date
Iterator callsItr = calls.iterator();


while (callsItr.hasNext()) {

i++;

//for each call in the call list
CallCycleGridCellVO cellVO = (CallCycleGridCellVO) callsItr.next();

//we compare "actual" vs "scheduled" date of the single call passed in depending on its status
if ("CMIE".equals(call.getStatusCd())) {

//if the single call's date is either before or equal to a call in the list,
//then the single call gets that call's order number
//all other calls get reordered after that
if ( (call.getActualCallDte().before(cellVO.getCall().getActualCallDte())) ||
(call.getActualCallDte().equals(cellVO.getCall().getActualCallDte())) ) {

orderNum = cellVO.getCall().getBaselineCallOrderNum().intValue();
break;

}

}
else {

// if the single call's date is either before or equal to a call in the list,
//then the single call gets that call's order number
//all other calls get reordered after that
if ( (call.getScheduledDte().before(cellVO.getCall().getScheduledDte())) ||
(call.getScheduledDte().equals(cellVO.getCall().getScheduledDte())) ) {

orderNum = cellVO.getCall().getBaselineCallOrderNum().intValue();
break;
}

}

}
call.setBaselineCallOrderNum(new Integer(orderNum));
sess.save(call);

for (int j=0; j<calls.size(); j++) {

//skip all calls that do not need to be modified (which are already in the right order)
//if a call in the list needs to be modified
if (j+1 >= i) {

CallCycleGridCellVO cellVO = null;

if (callsItr.hasNext())
cellVO = (CallCycleGridCellVO) callsItr.next();
else
break;

Call c = cellVO.getCall();
//set the right order number
c.setBaselineCallOrderNum(new Integer(orderNum++));
//save the call changes
sess.update(c); <b><<---- PROBLEM IS HERE</b>
t.commit();


}
//else skip this call
else {
CallCycleGridCellVO tempVO = (CallCycleGridCellVO) callsItr.next();
if (tempVO==null)
break;
}
}

sess.close();

}
catch (MappingException me) {
System.out.println(me);
}
catch (HibernateException he) {
System.out.println(he);
}
return 0;

}



Name and version of the database you are using: MySQL


----------------------

EXCEPTION :

net.sf.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: com.psadirect.hibernate.CallPK@7d32cf[callId=3,subscriber=com.psadirect.hibernate.Subscriber@86506a[subscriberId=1]], of class: com.psadirect.hibernate.Call


Hi guys,

I'm not a Hibernate pro, but I have read up on the "NonUniqueObjectException" on this forum, and I still cannot understand what the right way of doing things is.

Here is what I am trying to do :

I have a collection of calls
I need to iterate thru this collection, modify some props of each call and then update that call

Hibernate throws this exception on the 2nd pass thru the loop's update code. (pls see code where I have indicated that PROBLEM IS HERE)

Can someone please :

a) explain to me why this problem occurs ?
b) how can I bypass it ? I tried using saveOrUpdateCopy() and it did not seem to work for me.

Please spend a little time and explain to me how to bypass this problem.

Thanks,
SC


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

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.