DISQUS

DISQUS Hello!  The comments on this profile are unclaimed and thus are unverified.

Do they belong to you? Claim these comments.

rzei's picture

Unregistered

Feeds

aliases

  • rzei

rzei

8 months ago

in What you didn't think you needed to know about hashCode and equals on Thinking inside a bigger box
From a Hibernate users standpoint, could you give an example of a situation where you need to store a hashset of objects of which some are persisted, some get persisted why stored in set and some do not?

If you declare that id shouldn't be used in hashCode; in the same way you could say that you cannot use any fields in hashCode, as every one of those can change.

Surrogate should be the most stable property of an persist entity as it changes only once.

Great post though, too few have been written on the subject.
1 reply
jhannes Hi, rzei

The example wasn't very clear. I've run into the the problem in the following situations: I have a Parent object that includes many Children in a HashSet. I construct a new Parent and add Children to it, then I persist the Parent for the first time, and the HashSet is configured persisted as well, through cascading.

The result is that the Child objects are given an id, their hashCode change, and I can no longer find them.

Hope this was clearer?
Returning? Login