Is this a case for optimistic-locking perhaps? On Tue, Feb 17, 2009 at 2:27 PM, Fabio Maulo <[email protected]> wrote:
> Not clear for me... please review your code. > > 2009/2/17 Nuno Lopes <[email protected]> > > >> Hello, >> >> I have the following problem looking for a NHIbernate solution. >> >> Suppose we have an object objA business rules depend on the state of >> objB. >> >> Say you have to classes A and B: >> >> >> // start tranasction >> A objA = (A) session.Get(typeof(A), aID); >> B objB = (B) session.Get(typeof(B), aID); >> a.DoSomeChanges(b); >> // end transaction >> >> The DoSomeChangesMethod of A does this: >> >> void DoSomeChanges() >> { >> if (b.Test() >> this.propA = 23; >> } >> >> The method Test() on B does this; >> >> bool Test() >> { >> return this.propB == "Hello Word"; >> } >> >> Notice that objB state is not changed in this process so it is not >> Dirty. >> >> My problem is that when objA is persisnted it might be the case the >> state of objB are no longer valid (its state in the DB was changed by >> some other process also using NHibernate). >> >> How can I force NHibernate to check if the state of objB was not >> changed while saving objA (in a single transaction)? >> >> As far as I understand every time an object is saved, its version is >> increased. Also NHibernare rises an exception if the version of the >> object being saved is too old in comparison with the one thet is >> stored. It also does not save the object if the version is current. >> >> If that is the case, I thought about forcing objB along with objectA >> to be saved in order for its version to be checked. That way the state >> of objB would be the most current. But I don't know how to do this >> either. >> >> I also would want to enforce this behaviour in the way that my code >> above does not need to know that the state of objB need to be checked. >> >> Anyway, what would you experience NHibernate user do in this case? >> I'm sure it is not unique, probably NHibernate already deals with this >> automatically, I just don't know. >> >> Any help would be appreciated. >> >> Nuno >> >> >> >> >> >> >> >> >> >> >> >> > > > -- > Fabio Maulo > > > > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
