https://kotlinlang.org logo
#announcements
Title
# announcements
c

Czar

11/19/2017, 6:45 PM
@ziad using
String#hashCode
for this is a really bad idea
z

ziad

11/20/2017, 10:11 AM
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

Czar

11/20/2017, 11:23 AM
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

ziad

11/20/2017, 11:24 AM
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

Czar

11/20/2017, 11:54 AM
You're welcome. AFAIK K Exposed does not have built in auditing, but yes, it should be trivial to implement manually.
z

ziad

11/20/2017, 11:54 AM
😃
3 Views