-->
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: NonUniqueObjectException when save object
PostPosted: Sat Jan 02, 2010 12:51 pm 
Beginner
Beginner

Joined: Mon Feb 02, 2009 3:22 am
Posts: 26
hi,

I got an error when I insert a large number of records into mySQL database by the following method:

public void saveUpdateOfBatch(Vector<Object> dataVector)
{
Session session = HibernateSessionFactory.getSession();
Transaction tr = session.beginTransaction();

for (int i = 0; i < dataVector.size(); i++)
{
session.saveOrUpdate(dataVector.elementAt(i));

if (i % 50 == 0)
{
session.flush();
session.clear();
}
}
tr.commit();
session.close();
}

The exception is :

org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session。

I understand this error would happen when two records have the same primmary key, so in this metohd I chose to use saveOrUpdate to avoid this kind of error , but it still happened. I don't understand.

Would anybody explain this? and How should I do? At least I'd like to locate which record cause this problem, but the error message is not detail enough for me to do that.


Thanks


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.