Java – what is the best practice when implementing equals () with entities that generate IDS?

If I have a table a, B, C, D

Now, if I'm going to create a business object based on this table (for example, in Java), which better implements the equals () method:

>Define equality based on a > define equality based on B and C

Or, the two I choose are unimportant

Solution

Absolute B and C, because you want the equals () contract to be valid even before entity persistence You said yourself:

If so, that's the logic that equals () should use Database key is the focus of database and should be independent of your business layer

And don't forget to use the same attributes in hashcode ()

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>