-->
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.  [ 4 posts ] 
Author Message
 Post subject: determine if column has to be changed
PostPosted: Mon May 02, 2005 8:28 am 
Beginner
Beginner

Joined: Fri Nov 19, 2004 11:38 am
Posts: 29
Hi,
is it possible before calling session.save to determine if a certain column of the pojo passed as parameter was changed by the user.
I'd like to put some business logic control only if the column has been modified by the user.
Thanks

Simone


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 02, 2005 10:59 am 
Regular
Regular

Joined: Mon Jul 26, 2004 2:28 pm
Posts: 86
Location: Pensacola, Florida
You can enable dirty checking in Hibernate (select-before-update="true" in <class>), but I'm don't think you can narrow it down to a specific column, and there are performance implications. You could create an interceptor that implements onSave and/or onFlushDirty that will compare two states of the object. There are two ways to do this:

1) Use the object ID to load the object's current persisted state and compare. To do this you would have to set the session to FlushMode.COMMIT or FlushMode.NEVER to allow a "dirty" load (FlushMode.AUTO will perform the insert/update before performing the select). This requires no modification to the POJO.

2) Use the POJO setters to initialize an explicit dirty flag (perform compare on set). Have your interceptor look for that flag and handle appropriately. You will need to set access="field" in your mapping file for the affected properties to avoid setting the dirty flag when the object is initialized by Hibernate. That, or provide a separate group of setters (private access) explicitly for Hibernate that avoid the compare. This is probably cleaner and will avoid unwanted side-effects of messing with the session's FlushMode.

- Jesse


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 05, 2005 5:32 am 
Beginner
Beginner

Joined: Fri Nov 19, 2004 11:38 am
Posts: 29
Thank you very much Jesse for the precious suggestions.
Simone


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 10, 2005 9:58 am 
Regular
Regular

Joined: Mon Jul 26, 2004 2:28 pm
Posts: 86
Location: Pensacola, Florida
I just discovered that the onSave( ) and onFlushDirty( ) methods in the Interceptor actually provide both the old and new object states, so you can disregard that whole bit about FlushMode and loading from the database...

- Jesse


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