Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version: 3.0.5
Name and version of the database you are using: oracle10g
I am having trouble updating an object outside of a session. I thought that the following case makes perfect sense:
session 1:
save an object from to the database
outside of the session:
update the object, set some properties
session 2:
re-attach the object, and update it (using update() or saveOrUpdate())
well, for some strange reason this doesn't work for me at all. I tried using a second approach:
session 1:
get an object from to the database
session 2:
update the object, set some properties and then call update()
this too failed on me. I then tried a 3rd approach, which is quite silly, but I thought I'd give it a try
session 1:
save an object to the database
session 2:
get the same object again using it's pk (even though the original object is still in my hands)
update the object, set some properties and then call update()
surprise surprise - it fails!
where can I be doing something wrong? what might cause it? I keep getting
08/03/2006 14:23:57 org.hibernate.event.def.AbstractFlushingEventListener performExecutions
SEVERE: Could not synchronize database state with session
org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [com.taldor.ko.datamodel.vo.Site#916]
at org.hibernate.persister.entity.BasicEntityPersister.check(BasicEntityPersister.java:1441)
at org.hibernate.persister.entity.BasicEntityPersister.update(BasicEntityPersister.java:1986)
at org.hibernate.persister.entity.BasicEntityPersister.updateOrInsert(BasicEntityPersister.java:1909)
at org.hibernate.persister.entity.BasicEntityPersister.update(BasicEntityPersister.java:2149)
at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:75)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:239)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:223)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:137)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:274)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:730)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:324)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:86)
after running this SQL command:
Hibernate: update SITE set UPDATE_TIME=?, SITE_CODE=?, SITE_TYPE=?, REGION=?, WORK_MODE=?, DEFAULT_CODEC=?, VERSION=?, CREATION_TIME=? where SITE_ID=? and UPDATE_TIME=?