In JPA, you might have multiple versions of the same database row in memory in different objects. Like if you fetch a row and make changes to it. The only way that JPA can distinguish between the "before" and "after" versions of that row - instead of confusing them with other rows in the database is to consider them as the same row (equals) by comparing ONLY the keys of that object. Since hashCode must track equals(), that means customizing hashCode to hash only on the key field(s) as well.
Mike Gosling wrote:
This is probably correct, but I don't think that is the reason why I'm getting error above. Project is two and a half year in production without hash and equals.
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koophttps://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton