You mean the 'previousState' argument of OnFlushDirty? I hope not,
because that's null. The entity has been changed on the client and is
stored in a new session, so the old state is not in the cache.
pseudo-code:
client side:
entity = server.GetIt()
entity.Property = 3
server.Store(entity)
server side Store:
using (session = new Session())
{
session.BeginTransaction()
session.SaveOrUpdate(entity)
session.Commit()
}
NHibernate would need to get the old state from the database, which
would cause unnecessary queries. Instead it just updates the record,
that's actually what I usually expect.
I also tried select-before-update in the mapping file, this causes
NHibernate to query the old state but it does not provide it in
OnFlushDirty (there is also a forum post about this, but I can't
remember where it was).
I really hope that you mean something else ...
On 11 Nov., 14:28, "Ayende Rahien" <[EMAIL PROTECTED]> wrote:
> Why are you trying to get the values from the DB?NH will give you the old
> values, and you can ensure that it will behave well with optimistic
> concurrency
>
> On Tue, Nov 11, 2008 at 1:04 PM, Stefan Steinegger <[EMAIL PROTECTED]>wrote:
>
>
>
> > I'm struggling with the classical audit log problem. I'm using an
> > NHibernate Interceptor to get called when anything is stored. We have
> > a three tier architecture and the changes on the entities mostly occur
> > outside of a session. Now I need to get the original values from the
> > database to compare with.
>
> > NHibernate's cache is becoming a Nightmare. Here is what I tried until
> > now:
>
> > - Open another Session on the same transaction
> > newSession = factory.OpenSession(OriginalSession.Connection)
> > Problem: when I dispose the new Session, the transaction gets closed
> > and my original session can't complete. It actually works if I just
> > don't dispose the new session. But this does not seam to be a serious
> > solution to me.
>
> > - Open another Session with on a new connection
> > newSession = factory.OpenSession()
> > There are several problems with this. First, I can't use database
> > isolations anymore. It will still be consistent with NHibernates
> > optimistic locking, but we don't use this for all entities.
> > The much bigger problem I have is that we use Sqlite for testing,
> > where I can't open a new connection because Sqlite creates a new
> > database for every connection. So I need to use the same transaction
> > and get stuck with the problem above.
>
> > - Calling LoadDatabaseSnapshot
>
> > OriginalSession.GetSessionImplementation().GetEntityPersister(entity).GetDatabaseSnapshot(...)
> > You probably can see that I really got desperate. Actually, it would
> > be VERY NICE to have a method on the session like GetDatabaseSnapshot
> > and you get a new instance of the entity, not from cache, but from the
> > database. EntityPersister.GetDatabaseSnapshot has a big drawback. You
> > get the "dehydrated" state of the entity. This would be actually even
> > better than a real instance, because you don't need reflection to get
> > the values. But you won't get any references or lists. So I would need
> > subsequent queries to get them, which will be complicated (needs NH
> > metadata inspection) and very slow.
>
> > Any idea how to solve this problem would be much appreciated.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---