<@U5NANKKA7> using `String#hashCode` for this is a...
# announcements
c
@ziad using
String#hashCode
for this is a really bad idea
z
Thanks for following up on this 😃 Other than a timestamp, what would you recommend as a good way to check if an object has changed?
c
IMO, timestamping is the best solution with a ton of ready made db auditing utilities, like Hibernate Envers, or Spring Data's
@LastModifiedDate
As for an alternative, you could use any of the number of available hash functions, like MD5, or SHA* variants. Problem is with hashes you have to always remember about collisions. Since you're working with JSON (so I assume somewhat long strings with small changes) all hashes I've mentioned should in theory provide very small collision rate. From what I understand though you're trying to get better performance, timestamps will be much more performant than hashes. Another idea, instead of a timestamp you could keep an autoincrement field which you increment on each update, so it is effectively your data's version. Some data access libraries even support that, Spring Data for example has
@Version
annotation.
z
That’s very useful, thanks!. I am in fact using Spring, with Kotlin Exposed, not sure if I can make use of the annotations or not, but even if I have to implement the timestamp stuff myself it shouldn’t be too difficult. Thanks again for taking the time to share your thoughts.
c
You're welcome. AFAIK K Exposed does not have built in auditing, but yes, it should be trivial to implement manually.
z
😃