I have a table whose PK consists of two short varchars (15 and 5) and one datetime field.
My thoughts on creating a hashCode was to formate the datetime to something like yyyyMMddHHmmss and then concatenate it with the other two fields using some delimiter (e.g. _) and then ask for the hash code on that string.
Was wondering if there may be a more elegant approach.
Thanks
All depends on what you mean by “bulletproof”. If you just mean it can be used as the
hashCodeof a Java object, then it should be fine. Doesn’t Hibernate return a datetime as a javaDate? If so, just usehashCodeon thatDate. You can xor (or add, …) with the otherhashCodes instead of concatenating and hashing, it may be a bit faster.If by “bulletproof” you need a cryptographically secure hash, then you need to do more.