When I update a transient object,
the changes get persisted to the DB even though the following HibernateException gets thrown. I'm using MS Sql Server and the Microsoft JDBC drivers. Anyone know why?
12:58:13,930 ERROR [SessionImpl] Could not synchronize database state with session
net.sf.hibernate.HibernateException: SQL update or deletion failed (row not found)
at net.sf.hibernate.impl.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:25)
at net.sf.hibernate.persister.EntityPersister.update(EntityPersister.jav
a:672)
at net.sf.hibernate.persister.EntityPersister.update(EntityPersister.jav
a:625)
at net.sf.hibernate.impl.ScheduledUpdate.execute(ScheduledUpdate.java:52)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2308)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2262)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2187)
Code:
public void save(Object o) {
Session session = null;
try {
// open session
session = sessionFactory.openSession();
// save Object
session.saveOrUpdate(o);
// flush session
session.flush();
// close session
closeSession(session);
} catch (HibernateException e) {
log.fatal("Error occurred while saving object", e);
closeSession(session);
}
}