I declared, to use managed versioning, but didn't get
a StaleObjectStateException when concurrently modifiying
a row
Instead I got "SQL insert, update or delete failed (row not found)".
Best Regards
Hibernate version:
hibernate-2.1.6
Mapping documents:
<hibernate-mapping>
<class name='hibernate.Message' table="marchart_messages">
<id name="id" column="message_id"><generator class="increment"/></id>
<version name="version" column="VERSION"/>
<property name="text" column="message_text"/>
<property name="countmessages" formula="( select count(message_text) from marchart_messages )" ></property>
<many-to-one name="nextMessage" cascade="all" column="next_message_id"/>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
Transaction tx = session.beginTransaction();
Message message = (Message) session.get(Message.class, new Long(1));
System.out.println("Message text is: " + message.getText());
System.out.print("Enter a new text: ");
message.setText(br.readLine());
tx.commit();
Full stack trace of any exception that occurs:
15:55:07,688 ERROR SessionImpl:2379 - Could not synchronize database state with session
net.sf.hibernate.HibernateException: SQL insert, update or delete failed (row not found)
at net.sf.hibernate.impl.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:25)
at net.sf.hibernate.persister.EntityPersister.update(EntityPersister.java:684)
at net.sf.hibernate.persister.EntityPersister.update(EntityPersister.java:642)
at net.sf.hibernate.impl.ScheduledUpdate.execute(ScheduledUpdate.java:52)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2418)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2372)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2240)
at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)
at hibernate.A02_SessionGranularitaetCopy.main(A02_SessionGranularitaetCopy.java:42)
Debug level Hibernate log excerpt:
2nd failing Process:
Enter a new text: Tobi
16:05:00,594 DEBUG JDBCTransaction:59 - commit
16:05:00,594 DEBUG SessionImpl:2246 - flushing session
16:05:00,594 DEBUG Cascades:497 - processing cascades for: hibernate.Message
16:05:00,594 DEBUG Cascades:113 - cascading to saveOrUpdate()
16:05:00,594 DEBUG SessionImpl:1372 - saveOrUpdate() persistent instance
16:05:00,594 DEBUG Cascades:506 - done processing cascades for: hibernate.Message
16:05:00,594 DEBUG Cascades:497 - processing cascades for: hibernate.Message
16:05:00,594 DEBUG Cascades:113 - cascading to saveOrUpdate()
16:05:00,594 DEBUG SessionImpl:1372 - saveOrUpdate() persistent instance
16:05:00,594 DEBUG Cascades:506 - done processing cascades for: hibernate.Message
16:05:00,594 DEBUG Cascades:497 - processing cascades for: hibernate.Message
16:05:00,594 DEBUG Cascades:506 - done processing cascades for: hibernate.Message
16:05:00,594 DEBUG Cascades:497 - processing cascades for: hibernate.Message
16:05:00,594 DEBUG Cascades:113 - cascading to saveOrUpdate()
16:05:00,594 DEBUG SessionImpl:1372 - saveOrUpdate() persistent instance
16:05:00,594 DEBUG Cascades:506 - done processing cascades for: hibernate.Message
16:05:00,594 DEBUG SessionImpl:2439 - Flushing entities and processing referenced collections
16:05:00,609 DEBUG AbstractEntityPersister:275 - hibernate.Message.text is dirty
16:05:00,609 DEBUG SessionImpl:2533 - Updating entity: [hibernate.Message#1]
16:05:00,609 DEBUG Versioning:26 - Incrementing: 10 to 11
16:05:00,609 DEBUG SessionImpl:2780 - Processing unreferenced collections
16:05:00,609 DEBUG SessionImpl:2794 - Scheduling collection removes/(re)creates/updates
16:05:00,609 DEBUG SessionImpl:2270 - Flushed: 0 insertions, 1 updates, 0 deletions to 4 objects
16:05:00,609 DEBUG SessionImpl:2275 - Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
16:05:00,609 DEBUG Printer:75 - listing entities:
16:05:00,609 DEBUG Printer:82 - hibernate.Message{nextMessage=Message#4, text=drei, countmessages=4, id=3, version=0}
16:05:00,609 DEBUG Printer:82 - hibernate.Message{nextMessage=null, text=vier, countmessages=4, id=4, version=0}
16:05:00,609 DEBUG Printer:82 - hibernate.Message{nextMessage=Message#3, text=zwei, countmessages=4, id=2, version=0}
16:05:00,609 DEBUG Printer:82 - hibernate.Message{nextMessage=Message#2, text=Tobi, countmessages=4, id=1, version=10}
16:05:00,609 DEBUG SessionImpl:2359 - executing flush
16:05:00,625 DEBUG EntityPersister:648 - Updating entity: [hibernate.Message#1]
16:05:00,625 DEBUG EntityPersister:649 - Existing version: 10 -> New version: 11
16:05:00,625 DEBUG BatcherImpl:200 - about to open: 0 open PreparedStatements, 0 open ResultSets
16:05:00,625 DEBUG SQL:226 - update marchart_messages set VERSION=?, message_text=?, next_message_id=? where message_id=? and VERSION=?
16:05:00,625 DEBUG BatcherImpl:249 - preparing statement
16:05:00,625 DEBUG EntityPersister:388 - Dehydrating entity: [hibernate.Message#1]
16:05:00,641 ERROR SessionImpl:2379 - Could not synchronize database state with session
net.sf.hibernate.HibernateException: SQL insert, update or delete failed (row not found)
at net.sf.hibernate.impl.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:25)
at net.sf.hibernate.persister.EntityPersister.update(EntityPersister.java:684)
at net.sf.hibernate.persister.EntityPersister.update(EntityPersister.java:642)
at net.sf.hibernate.impl.ScheduledUpdate.execute(ScheduledUpdate.java:52)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2418)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2372)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2240)
at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)
at hibernate.A02_SessionGranularitaetCopy.main(A02_SessionGranularitaetCopy.java:42)
net.sf.hibernate.HibernateException: SQL insert, update or delete failed (row not found)
at net.sf.hibernate.impl.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:25)
at net.sf.hibernate.persister.EntityPersister.update(EntityPersister.java:684)
at net.sf.hibernate.persister.EntityPersister.update(EntityPersister.java:642)
at net.sf.hibernate.impl.ScheduledUpdate.execute(ScheduledUpdate.java:52)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2418)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2372)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2240)
at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)
at hibernate.A02_SessionGranularitaetCopy.main(A02_SessionGranularitaetCopy.java:42)
|