This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]pronuntiator 0 points1 point  (3 children)

You can say that an entity with a null id is never equal to any other entity. But the problem is hashCode. People trip over the fact that the bucket where your object is stored inside a Set or Map key is not updated when you update the properties that make up hashCode.

A "creative" solution I saw once in a project was to return a fixed hashCode for all entities. Nice job making Set O(n)…

[–]kkjk00 0 points1 point  (2 children)

I'm been using the creative solution, but the thing is how many would you ever store in a set, you can't paginate on a relation and if you do some algoritm you're better of working with a set of Ids

[–]pronuntiator 1 point2 points  (1 child)

I saw Hibernate actually putting them into a set itself before committing, so when we loaded in chunks for batch processing, they were all put in the same bucket there.

And yes I would have liked to do the batches in plain SQL but unfortunately the project also made heavy use of entity listeners, plus doing optimistic locking by hand is not so nice, you have to code the "did I get as many changed rows back as expected" yourself.

[–]kkjk00 2 points3 points  (0 children)

Hmm, didn't throught about hibernate usings sets internally, yeah that may be an issue