-->
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.  [ 4 posts ] 
Author Message
 Post subject: Optimistic lock exception
PostPosted: Sat Sep 24, 2005 11:32 am 
Contributor
Contributor

Joined: Sat Sep 24, 2005 11:25 am
Posts: 198
I'm testing some features in NHibernate, and I got to a point where I'm not sure if I got the desired behavior or not.
The scenario is like this:
* A class with mapping that has optimistic-lock=all and dyanmic-insert and dynamic-update set to true.

* Creating the class and saving to database.
* Loading the object in another session, changing it and saving back to db.
* Updating the object on the first session and trying to save to database.

I get an ADOException with the message "could not update: [classname:ID]"

I expected to get a StaleObjectException.

Is this the expected behavior?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 24, 2005 1:27 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Probably not, this looks more like NH generated wrong SQL or something like that. Can you post the whole exception stack trace (including inner exceptions)?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 24, 2005 2:20 pm 
Contributor
Contributor

Joined: Sat Sep 24, 2005 11:25 am
Posts: 198
It looks like the inner exception is the correct result, but it's not recognizing a stale object.

NHibernate.ADOException occurred
Message="could not update: [Hilan.WorkScheduler.Model.BoardType#13]"
Source="NHibernate"
StackTrace:
at NHibernate.Persister.EntityPersister.Update(Object id, Object[] fields, Object[] oldFields, Boolean[] includeProperty, Object oldVersion, Object obj, SqlString sqlUpdateString, ISessionImplementor session)
at NHibernate.Persister.EntityPersister.Update(Object id, Object[] fields, Int32[] dirtyFields, Object[] oldFields, Object oldVersion, Object obj, ISessionImplementor session)
at NHibernate.Impl.ScheduledUpdate.Execute()
at NHibernate.Impl.SessionImpl.Execute(IExecutable executable)
at NHibernate.Impl.SessionImpl.ExecuteAll(IList list)
at NHibernate.Impl.SessionImpl.Execute()
at NHibernate.Impl.SessionImpl.Flush()
at Hilan.WorkScheduler.DataLayer.Database.PersistChanges() in E:\Hilan.WorkScheduler\Hilan.WorkScheduler.DataLayer\Database.cs:line 313

NHibernate.HibernateException
Inner Exception: {"SQL insert, update or delete failed (expected affected row count: 1, actual affected row count: 0). Possible causes: the row was modified or deleted by another user, or a trigger is reporting misleading row count."}

Stack Trace:
at NHibernate.Impl.NonBatchingBatcher.AddToBatch(Int32 expectedRowCount)
at NHibernate.Persister.EntityPersister.Update(Object id, Object[] fields, Object[] oldFields, Boolean[] includeProperty, Object oldVersion, Object obj, SqlString sqlUpdateString, ISessionImplementor session)


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 25, 2005 7:04 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
I was able to fix it only partly. You will get a HibernateException now, not wrapped inside an ADOException. But fixing NH to throw StaleObjectStateException would require making some changes to internal Hibernate APIs and I don't want to make the changes at this time, especially since Hibernate 2.1 also throws HibernateException instead of StaleObjectStateException in this case. This issue is NH-385 in JIRA.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.