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
|
|