-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: StaleObjectStateException
PostPosted: Tue Oct 12, 2004 11:07 am 
Newbie

Joined: Fri Oct 01, 2004 8:41 am
Posts: 8
Location: Vienna
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)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 13, 2004 4:31 am 
Expert
Expert

Joined: Tue Oct 05, 2004 9:45 am
Posts: 263
that actually fit's to the 'problem' we found in this thread.

It seems that the 'NonBatchingBatcher' reacts different than the AbstractEntityPersister though it's the same situation ... got no answer yet if i had some mistakes in my thoughts ... but this seems to be the same ..

gtx
curio


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 13, 2004 7:50 am 
Newbie

Joined: Fri Oct 01, 2004 8:41 am
Posts: 8
Location: Vienna
curio wrote:
that actually fit's to the 'problem' we found in this thread.

It seems that the 'NonBatchingBatcher' reacts different than the AbstractEntityPersister though it's the same situation ... got no answer yet if i had some mistakes in my thoughts ... but this seems to be the same ..

gtx
curio


Hi, thx for your reply, but your problem seems to be even more complex, cause you're dealing with caching...

I did't turn on caching and the Excaption is not thrown.

Best Regards


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 13, 2004 8:12 am 
Expert
Expert

Joined: Tue Oct 05, 2004 9:45 am
Posts: 263
hi marchart,

I've got the mentioned Exception with or without caching. My last tests were without caching.

Quote:
I did't turn on caching and the Excaption is not thrown.

The Exception isn't thrown? I thought that's the problem? ;)

For me it's a workaround (at the moment) to interpretate the "row-not-found"-exception as "StaleObjectException" because the situation on which this exception gets thrown is in my eyes the same ...

Even the difference between our concurrency-handling (you use versioned-check and i use "check all fields") is not important i think ... the 'NonBatchingBatcher' will be called in both cases (if batching is turned off on 'jdbc-level') ...

gtx
curio


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 13, 2004 10:18 am 
Newbie

Joined: Fri Oct 01, 2004 8:41 am
Posts: 8
Location: Vienna
Quote:
I did't turn on caching and the Excaption is not thrown
The Exception isn't thrown? I thought that's the problem? ;)
.


No, I expected to catch the StaleObjectException but it was not thrown

Best Regards


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 13, 2004 10:56 am 
Expert
Expert

Joined: Tue Oct 05, 2004 9:45 am
Posts: 263
if i'm right, the StaleObjectException won't be thrown during updates as long as the NonBatchingBatcher-Class is used ...

why it is used in your case i cannot say ... perhaps you've set the "hibernate.jdbc.batch_versioned_data"-Attribute in your config-file?! But that's only a 'blind shot' ...

A good starting-point for looking in hibernate-src is the EntityPersister in line 683. The method "isBatchable()" must return 'true' in your case ... using version-checking means, that the mentiond property must be set ... (i would say if i'm not wrong ;) )

gtx
curio


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.