Open source reader

Friday, September 22, 2006

*!* Hibernate users, do not skip this *!* The great object Equals and hashCode pattern proposal !

Hi all,

now it is the time to get back on of the nastiest problem of hibernate

Looks like there is a valuable solution posted here !

Does it work ? Yes !
passes successfully the 3 tests listed above in the article:
- "multiple new instances in set"
- "equal to same object from other session"
- "collections intact after saving"
The principals ?
The first time equals or hashCode is called, we check if the
primary key (here getUserId()) is present or not.
If yes: we use it in equals/hashcode
If no: we use a UID (here _uidInEquals) during the entire life of this
instance even when latter on this instance is assigned a primary key.
And there is the sample code too using java.rmi.dgc.VMID !

That's good news for the hibernate community !
Happy O/R'ing !