We made a conscious decision NOT to override the default
implementations of equals and hashCode, and rely exclusively on object
identity. There are the known limitations, of course, but they haven't
been much of a problem in practice. We rarely have a need to "mix" two
objects with the same database identity loaded from two different
sessions. And when we do, we create an inner class that encapsulates
the business key from the entity and use that as the key into maps and
such.
It may not address all cases perfectly, but it's consistent and easy
to follow. |