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
|