All objects should have a valid equals() method. If the PK class inherits the equals() method, this means that two references to an instance will return true if the equality operator is used. As this is not always correct, the programmer may have to override the equals() method and should almost certainly also overrride the hashCode() method as well.
besides, EJB spec says: PK "class must provide suitable implementation of the hashCode() and equals(Object other) methods to simplify the management of the primary keys by client code" and "container".
I ran across a more detail explanation for this, on container level: "the primary key class must be Serializable. This allows the client and server to exchange keys using by value semantics." ... "Because we will be passing keys by value the issue of object identity comes up. Passing by value means that multiple copies of an object can exist. The server will at times compare keys for equality. The default implementation of equals inherited from the Object class uses identity. This will cause problems when comparing copies, therefore we must override equals. Because we override equals we must also override hashCode." (excerpted from http://users.bigpond.net.au/stephen.davies/papers/beanKeys.html)
On client level, override for the 2 methods in PK class is optional, technically. The spec suggests always use isIdentical() to distinguish entity object references.
Well, taking into account the need in container level, the override is necessary.
It's hard to fight evil. The little things, like a nice sandwich, really helps. Right tiny ad?