Entity Beans: equals and hashCode methods
Object equality can be checked using any of the two methods of the Object class and these are equals and hashCode. Because ,if two objects are same, equals should return a value of zero. Also, in this case hash codes of both the objects are same. My question is whether it necessary to write both equals and hashCode methods in the Entity Bean classes? Please illuminate.
[378 byte] By [
maitya] at [2007-10-3 4:27:29]

Object.equals() returns a boolean. Therefore it returns true if two objects are equal. As to your specific question about Entity beans, I would actually implement the equals() and hashCode() methods in a Data Transfer Object (DTO). Entity beans are "heavyweight" instances and may contain Collections of other Entity beans as member variables. Iterating over these collections must be done inside transaction boundaries, so the Entity bean really shouldn't be used except to extract the data into the "lightweight" DTO.
With that caveat in mind, it makes perfect sense to implement the equals() and hashCode() methods for the Entity's DTO.
Brian