-->
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.  [ 3 posts ] 
Author Message
 Post subject: How to tell if a disconnected object has changes
PostPosted: Wed Feb 14, 2007 1:01 pm 
Newbie

Joined: Wed Feb 14, 2007 12:44 pm
Posts: 2
If I get the same object from two different sessions and make no changes object.Equals(sameobject) still equals false. What I want to do is store an object in the users asp.net session and then several requests later be able to let the user know if they have made any changes that they need to save. What's the best way to go about implementing this?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 15, 2007 2:28 am 
Senior
Senior

Joined: Mon Aug 21, 2006 9:18 am
Posts: 179
It depends on how you are implementing .Equals. Personally, I favor a 'Business key' comparison instead of an 'Identity key' comparison for exactly this kind of scenario...and because it is recommended in the Hibernate in Action book.
So instead of comparing based on the identifier value (id) you'd compare the immutable values in your class (perhaps 'name' or 'social security number').
Of course, this presumes some immutability exists in your class...which is usually the case or perhaps pointing to a design decision left undone.

The only other alternative I could think would be to reattach the object to the Session and then let NHib check the IsDirty state.

MIKE

_________________
If this helped...please remember to rate it!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 15, 2007 4:46 pm 
Regular
Regular

Joined: Fri Jan 27, 2006 2:32 pm
Posts: 102
Location: California, USA
mnichols wrote:
The only other alternative I could think would be to reattach the object to the Session and then let NHib check the IsDirty state.

MIKE


In my WinForms app, I use the ISession.IsDirty() method to see if a session has changes that have not been saved to the database.

However, this checks the entire session! So it doesn't tell me if a specific object has changes, only if the session has changes.

Brian


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