At first do not use SaveOrUpdate to reconnect disconnected entities, use refresh or lock.
I guess from your explaination you are using Flushmode.Auto in your session, consider using FlushMode.Commit that no longer auto flushes on a query. On 13 jan, 02:00, kzjkd6 <[email protected]> wrote: > We are trying to use nHibernate in a winform application. We are > using it in a session-per-business-activity model with entities that > are disconnected and then associated to sessions using SaveOrUpdate > (). > > We have the following scenario: > > App loads entity in Session 1. > Session 1 is closed. > App make changes to entity in response to user interaction > Session 2 is started > Transaction is started > Entity is associated with session > Query is made (which triggers a Flush and as a result the version > number is incremented on the dirty entity) > As a result of the business rules evaluated on the query results we > decide not to commit the transaction. > Transaction is rolled back. > Session 2 is closed. > > User is shown a message explaining the problem. > User fixed the problem (screen still bound to the same entity) > > Session 3 is started > Transaction is started > Entity associated with Session > Query is made again (which triggers another Flush and the version > number is incremented yet again) > Business Rule now satisfied > Transaction is committed. > --> Exception thrown because the version number no longer satisfies > the optimistic lock. > > I know we could throw away the user's changes and re-fetch the entity > when the business rule is initially violated but that represents a > huge pain for the users. I know we could do this and then re-apply > changes on the user's behalf but I am looking for a generic solution > as the object graph can be quite deep. > > What is the recommend way to get around this? > > Thanks. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "nhusers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/nhusers?hl=en -~----------~----~----~----~------~----~------~--~---
