-->
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: How to detect a dirty object?
PostPosted: Wed Dec 10, 2003 1:33 pm 
Beginner
Beginner

Joined: Sat Dec 06, 2003 5:38 pm
Posts: 27
Hi all,

I want to tell my users when an object is changed and then saved. However, I don't want to do anything weird with interceptors.. I was hoping there was something like:

Hibernate.isDirty(myObject) that would tell me if the object had been changed during the session?

Eric


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 10, 2003 5:08 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I'm afraid you have to go into the weirdness of the interceptors

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 10, 2003 5:22 pm 
Beginner
Beginner

Joined: Sat Dec 06, 2003 5:38 pm
Posts: 27
Theorectically I could look into how Hibernate detects whether an object is dirty or not.. Is my desire to leverage hibernate to detect a dirty object that odd? Just surprised since isInitialized is there on the Hibernate class....

I'll go hunting and see what I find. Thanks..
Eric


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 10, 2003 6:37 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
No, there are reasons why we don't support this: we only keep a snapshot of the most recent flush, so we don't know if anything changed before the flush.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 10, 2003 7:31 pm 
Beginner
Beginner

Joined: Sat Dec 06, 2003 5:38 pm
Posts: 27
That makes sense.. So, if I load up and object, and then do multiple flushes, I only know post the most recent flush whether the object is dirty or not.

So, what I could do is something icky like make a copy of the object and then using something compare all the properties to see what changes. However, since I only have one Session, with a flush at the end, assuming hibernate doesn't flush during, is there a way to see if things have changed?

I guess I could write an interceptor that tracked the changes to each object, and then query the interceptor for whether an object changed.....

Thanks,
Eric


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 10, 2003 7:36 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
interceptor solutions sounds most possible.

Remember that hibernate flushes automatically if you e.g. uses HQL to query stuff about any of the loaded object classes.

_________________
Max
Don't forget to rate


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.