users@glassfish.java.net

Re: JPA, equals and hashCode

From: <glassfish_at_javadesktop.org>
Date: Tue, 18 Dec 2007 16:48:45 PST

>
> Note that one of my -'s for option 2 is that you
> cannot put them into
> a collection...
>

I wasn't sure if that was what you meant, but then we're in agreement.

>
> Using @Id for hashcode is OK as long as you persist
> objects before
> putting them in a HashSet.
>

This sounds error prone to me.

>
> How do you handle the case where business keys
> change?
>

As a matter of fact, we haven't had to deal with this often. In the few cases where it's been an issue, we've used UUID. However, notice that the business "keys" don't have to be unique to be a good basis for hashCode.
[Message sent by forum member 'jhannes' (jhannes)]

http://forums.java.net/jive/thread.jspa?messageID=250665