what is root cause of this exception NHibernate.StaleObjectStateException: Row was updated or deleted by another transaction RRS feed

  • Question

  • below method not able to handle concurrency and throwing exception  (NHibernate.StaleObjectStateException: Row was updated or deleted by another transaction)

    In hibernate xml i am using <version name="DBVersion" column="DBVersion" type="Int64" generated="never" unsaved-value="0"/>

    public void Save(Object o)
                    // Check to make sure a session has been started, if not open a new session
                    if (_session == null)
                        _session = GetSession();

                    // Connect to the DB if necessary
                    // Start a transaction
                    // save
                    // commit
                catch (NHibernate.StaleStateException e)
                    string msg = "DB Stale data error.  Reason: " + e.ToString();
                //show error message
                    throw new ExceptionDatabaseStaleData(msg, e);

    Sunday, October 20, 2019 1:22 AM

All replies

  • in hibernate i am using optimistic locking 

     dynamic-update="true" optimistic-lock="version" lazy="false">

    Sunday, October 20, 2019 1:24 AM
  • Hi 000rakesh, 

    Thank you for posting here.

    According to your description, I note that your question is more related to NHibernate.

    NHibernate is a third-party product for which we don't provide help, so I suggest you post your question in NHibernate forum for more help.

    The CLR Forum discuss and ask questions about .NET Framework Base Classes (BCL) such as Collections, I/O, Regigistry, Globalization, Reflection. Also discuss all the other Microsoft libraries that are built on or extend the .NET Framework.

    Thank you for your understanding.

    Best Regards,

    Xingyu Zhao

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, October 21, 2019 9:27 AM