-
Nov 1st, 2007, 09:26 AM
#1
HibernateDaoSupport.saveOrUpdate problem
Hello everyone!
I've got an exception calling saveOrUpdate method after deleting and object. The following example demonstrates the problem
public class HiberTest {
public static void main(String[] args) {
Dumb dumb = new Dumb();
DumbDao dumbDao = new DumbDao() {
public void saveOrUpdate(Dumb obj) {
getHibernateTemplate().saveOrUpdate(obj);
}
public void delete(Dumb obj) {
getHibernateTemplate().delete(obj);
}
};
dumbDao.setSessionFactory(HibernateUtil.getSession Factory());
dumbDao.saveOrUpdate(dumb); // (1)
dumbDao.delete(dumb);
dumbDao.saveOrUpdate(dumb); // (2)
}
private static class DumbDao extends HibernateDaoSupport {
public void saveOrUpdate(Dumb obj) {
getHibernateTemplate().saveOrUpdate(obj);
}
public void delete(Dumb obj) {
getHibernateTemplate().delete(obj);
}
}
}
After the last call I get
Exception in thread "main" org.springframework.orm.hibernate3.HibernateOptimi sticLockingFailureException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1; nested exception is org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
Caused by: org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
at org.hibernate.jdbc.Expectations$BasicExpectation.c heckBatched(Expectations.java:61)
at org.hibernate.jdbc.Expectations$BasicExpectation.v erifyOutcome(Expectations.java:46)
at org.hibernate.jdbc.BatchingBatcher.checkRowCounts( BatchingBatcher.java:68)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch( BatchingBatcher.java:48)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(Ab stractBatcher.java:242)
at org.hibernate.engine.ActionQueue.executeActions(Ac tionQueue.java:235)
at org.hibernate.engine.ActionQueue.executeActions(Ac tionQueue.java:140)
at org.hibernate.event.def.AbstractFlushingEventListe ner.performExecutions(AbstractFlushingEventListene r.java:298)
at org.hibernate.event.def.DefaultFlushEventListener. onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.j ava:1000)
at org.springframework.orm.hibernate3.HibernateAccess or.flushIfNecessary(HibernateAccessor.java:388)
at org.springframework.orm.hibernate3.HibernateTempla te.execute(HibernateTemplate.java:363)
at org.springframework.orm.hibernate3.HibernateTempla te.saveOrUpdate(HibernateTemplate.java:676)
at HiberTest$1.saveOrUpdate(HiberTest.java:40)
at HiberTest.main(HiberTest.java:50)
I guess that the problem is that at point (1) and (2) objects have the same ids. Am I right? But I think that Spring must handle such situation. Is this a Spring bug or I've missed smth?
wheleph
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules