Consider that I’ve got a standard Java bean: i.e. it contains members that are String
, List
, HashMap
, etc.
My question is: what’s the easiest way to detect if an instance of such an object has been modified from say a previous/original state?
The reason I want to know this is so I determine whether I should update the object in the DB, or not, in the case where either: (i) no changes were made, or (ii) changes were made but then reversed.
I’ve been thinking about comparison of hashCode, or byte[], but doesn’t seem to work. Any ideas?
Yes, it can be done, and it has been done... it's called hibernate. Just use that and don't "reinvent the wheel"
if you have setters, notify a list of listeners in this setters if a new value is set.
The same problem had hibernate developers, and they've dealt with it by creating proxies for returned entities. The proxy registers each setter call and so determines if entity has changed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With