Hibernate version: 2.1.1
Mapping documents:
Code between sessionFactory.openSession() and session.close():
Full stack trace of any exception that occurs:
net.sf.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: 0, of class: com.gsk.les.bo.himpl.IHNotesDatabaseSpec
at net.sf.hibernate.impl.SessionImpl.checkUniqueness(SessionImpl.java:1605)
at net.sf.hibernate.impl.SessionImpl.doUpdateMutable(SessionImpl.java:1377)
at net.sf.hibernate.impl.SessionImpl.doUpdate(SessionImpl.java:1403)
at net.sf.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:1327)
at com.gsk.les.bp.himpl.IHBizObjBPs.genericBulkSaveOrUpdate(IHBizObjBPs.java:135)
at test.TestBulk.main(TestBulk.java:24)
Name and version of the database you are using: Oracle
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt:
I am attempting to create several transients and then conduct a bulk initial save of them. Here is an example of a simple (test) version that generates this issue:
Code:
BizObjBPs bps = BPFactory.createBizObjBPs();
NotesDatabaseSpec n1 = bps.createTransientNotesDatabaseSpec();
NotesDatabaseSpec n2 = bps.createTransientNotesDatabaseSpec();
List l = new ArrayList();
l.add(n1);
l.add(n2);
bps.genericBulkSaveOrUpdate(l);
The code in the "genericBulkSaveOrUpdate is:
Code:
int count = 0;
Session s = DBUtil.getDBUtilInstance().getSession();
Transaction tx = null;
try {
s.reconnect();
tx = s.beginTransaction();
for(Iterator it = l.iterator(); it.hasNext();) {
s.saveOrUpdate(it.next());
count++;
if(count >= BizObjBPs.BULK_GRP_SIZE) {
tx.commit();
tx = s.beginTransaction();
count = 0;
}
}
tx.commit();
} catch(Exception hex) {
if(tx != null)
try {
tx.rollback();
} catch(Exception ex2) {
ex2.printStackTrace();
}
hex.printStackTrace();
} finally {
try {
s.disconnect();
} catch(Exception hex) {
hex.printStackTrace();
}
}
Basically this code has worked in the past and suddenly I am getting this NonUniqueObjectException. Why is this not working?