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.  [ 2 posts ] 
Author Message
 Post subject: Object's Version
PostPosted: Fri Dec 22, 2006 4:39 am 
Newbie

Joined: Thu Dec 21, 2006 12:41 pm
Posts: 1
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:1.0.3.0

the data base contains a constraint of uniqueness on the object's name

Code:
protected virtual void Save(object obj)
        {
            ISession _session = null;
            DateTime _version = ((AbstractBaseEntity)obj).VersionTimeStamp;
            try
            {
                if(SessionScope.Current == null) _session = HibernateRegMgr.SessionFactory.OpenSession();
                else _session = SessionScope.Current;
                _session.SaveOrUpdate(obj);
                _session.Flush();
            }
            catch (HibernateException e)
            {
                //((AbstractBaseEntity)obj).VersionTimeStamp = _version;
                LogControler.LogError(ErrorMsg.SaveDAOError + obj.ToString(), e);
                HibernateExceptionAdaptator.ThrowCustomAppException(e);
            }
            catch (Exception e)
            {
                LogControler.LogError(ErrorMsg.SaveDAOUnexpectedError + obj.ToString(), e);
                throw new nSherpaDALGenericException(e);
            }
            finally
            {
                if(SessionScope.Current==null)CloseSession(_session);
            }

        }


when I save an object with a name whose exist in the database, an exception is thrown, it raise of the database.
The Problem is that the version (TimeStamp) of the object is incremented but it was not saved. that generate another problem when I want to sagve this object afterward, another exception is thrown because NHibernate want to do "Update" on the object but it does not exist in the database

The Second error message:
Quote:
2006-12-21 18:08:24,300 [2732] ERROR NHibernate.StaleObjectStateException [(null)] - An operation failed due to stale data
NHibernate.StaleObjectStateException: Row was updated or deleted by another transaction for nSHERPA.Core.NHibernateImpl.DML.Production.ProductionRequestStatus instance with identifier: dd05009a-0f10-4499-8df7-71c1b7dc2619
2006-12-21 18:08:24,300 [2732] ERROR NHibernate.Impl.SessionImpl [(null)] - could not synchronize database state with session
NHibernate.StaleObjectStateException: Row was updated or deleted by another transaction for nSHERPA.Core.NHibernateImpl.DML.Production.ProductionRequestStatus instance with identifier: dd05009a-0f10-4499-8df7-71c1b7dc2619


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 23, 2006 1:12 am 
Regular
Regular

Joined: Tue Feb 21, 2006 9:50 am
Posts: 107
This sounds like you have a problem with your session handling. I got the same error as i refactored handling of transactions in my application. The refactoring accidentially caused that i had two open sessions with an open transaction on the same object.

Regards
Klaus


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