gavin wrote:
OK, in your wish list above you did not specify:
- track exactly which properties changed
Sorry...I need to work on my specificity :(
Quote:
There is no really good way to track changes to a graph of POJOs at that fine level of granularity. So if you need something that granular, checking against the database is the simplest way.
It does take some extra work, but it can be done and I think the performance implications of avoiding the extra check against the database are worth considering it. If I had to implement this, I would do it this way:
1) Add property change events for each attribute on the POJO
2) When a property is first changed, record the original value in a Map
3) When items are added to and removed from collections, keep track of them also
4) When generating the SQL for updating the object, check the original values Map to determine what properties, if anything, has changed. The user could have an option of what to include the where clause to handle optimistic locking (pk only, pk + original values of changed fields, pk + original value of all fields).
5) Use the collection additions and deletions to determine how to reconcile dependent collections
I think I could implement steps 1, 2 & the first part of 4 in my own code now by using the Interceptor.findDirty() method. The part I need help from Hibernate is the collection stuff. If Hibernate could keep track of the additions and deletions to collections in it's collection proxies and use that to determine what changes were made to the collection, I think I'd be set. (Maybe you've added that already?)
I would think you could generalize this for all Hibernate users by either creating an interface that returned the original values of changed fields or adding an interceptor that captured changes to properties and kept track of the original value for them.
What are your thoughts?
Thanks,
John