We need to override default hashCode function. It will be used to calculate hashcode of an object. If generic function is impossible to implement, we should write hashCode function for all object classes or try a different approach.
Example of use:
You pull Patient category entity form Parent to Child. You calculate hashcode of pulled object and compare it with existing in Child instance hashcode saved on last pull of this object from Parent.
We should exclude at least date_voided,
date_changed from affecting hashcode. Hashcode should only be different for the same object if its fields were modified. Note that if you change i.e. name of this Patient to the same name, its name will be the same but date_changed will be updated. That is why we should exclude at least those two fields.
- hashCode function calculates hashcode for every object
- calculated hashcodes before and after updating i.e. name of a Patient to the same name should not differ
- calculating the same hashcode for two different objects should be very close to impossible
- We should also exclude entity id form the hashcode because they will be different in different openmrs instances for the same object.