-->
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.  [ 6 posts ] 
Author Message
 Post subject: IsDirty with transactions
PostPosted: Fri Feb 29, 2008 6:27 am 
Newbie

Joined: Sat Feb 23, 2008 2:51 pm
Posts: 10
Hi
When I didn't you transactions in NH I was able to check if there ware any changes during session (edit/del/add) by calling IsDirty(). But when I started to use transactions I noticed that IsDirty() almost always returns false (and it should, because FlushMode is Auto).

Is there any good way to check if there were any changes during transaction (from open or last commit) ?? My guess now is that I should track functions called by GUI.

Hibernate version:
1.2


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 29, 2008 11:53 am 
Expert
Expert

Joined: Fri Oct 28, 2005 5:38 pm
Posts: 390
Location: Cedarburg, WI
If you want to know what has been flushed (but not committed), you could implement IInterceptor.PostFlush(). The method is passed a collection of entities. However, I seem to recall that all entities in the session are passed, whether they were dirty or not. We do our own dirty tracking within our entities, so we can check the dirty status in IInterceptor.PreFlush() and IInterceptor.PostFlush(), and so that we can reset it in IInterceptor.PostFlush().


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 29, 2008 6:22 pm 
Newbie

Joined: Sat Feb 23, 2008 2:51 pm
Posts: 10
Well, I'm quite lazy, so I didn't mess with "functions in GUI" and I found the Interceptors on my own. But I didn't use PostFlush(). Instead I changed a flag in OnSave/OnUpdate/etc (isDataChanged = true).

Your way seems more clever but my already works :)

Andrew


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 01, 2008 5:06 am 
Expert
Expert

Joined: Tue Aug 23, 2005 5:52 am
Posts: 335
The problem you might find with your approach is that OnSave is only called when the entity is saved for the first time and OnUpdate is only called when a disconnected entity is re-attached to the session. As a result if you make changes to a loaded object while it remains attached to a session you won't know whether or not it's changed.

Cheers,

Symon.

_________________
Symon Rottem
http://blog.symbiotic-development.com


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 01, 2008 5:22 am 
Newbie

Joined: Sat Feb 23, 2008 2:51 pm
Posts: 10
Apparently you didn't noticed the "etc" in my statement ;)

To be clear, I change flag isDataChanged=true in: OnDelete, OnFlushDirty, OnSave.
And isDataChanged=false in: AfterTransactionBegin, AfterTransactionCompletion, SetSession (in case there's no transaction).

Andrew


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 01, 2008 7:58 am 
Expert
Expert

Joined: Tue Aug 23, 2005 5:52 am
Posts: 335
Quote:
Apparently you didn't noticed the "etc" in my statement ;)


*chuckle*

Looks like you're on top of it.

Cheers,

Symon.

_________________
Symon Rottem
http://blog.symbiotic-development.com


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