One thing to mention:

Be carefull with the generated equals()  / hashCode() or toString() methods.

If you have bidirectional mappings (e.g. user->roles and role->users) you
can run into a stackoverflow caused by infinit calls of e.g. the hashCode()
methods.
(user.hashCode() calls role.hashCode() wich calls user.hashCode() and so on)

Bye,

Peter

-----Ursprüngliche Nachricht-----
Von: Doubleday, Dennis [mailto:[EMAIL PROTECTED] 
Gesendet: Freitag, 23. Februar 2007 06:00
An: users@appfuse.dev.java.net
Betreff: RE: [appfuse-user] RE: Does Hibernate still require equals() and
hashCode()?

Right-click, Select Source-->Generate hashCode() and equals(). 

Pretty easy :-)

It should be pretty apparent how to fix it, just take out the offending
reference.

It lets you pick which fields you want to consider in the equality
comparison. If using Hibernate, you should use fields that form a natural
business key. DO NOT just compare IDs--read Hibernate in Action for the
reason.

Another thing--the Eclipse generated equals() code uses direct field
references to the other object rather than getters(). This does not work
reliably for Hibernate proxied objects. If you go through the getter, the
proxy will load the field if it hasn't be loaded yet, and the comparison is
correct. With direct field access, the proxy won't load the real object.
Very confusing the first time I saw this.

-----Original Message-----
From: Dean Jackson [mailto:[EMAIL PROTECTED]
Sent: Thursday, February 22, 2007 11:50 PM
To: users@appfuse.dev.java.net
Subject: [appfuse-user] RE: Does Hibernate still require equals() and
hashCode()?



How do you get Eclipse 3.2+ to generate them?

Also, what's the easy correction for equals()?


Dennis Doubleday wrote:
> 
> Eclipse 3.2 generates them without a plugin. It also assumes the 
> superclass has a non-abstract equals, but it is easy to correct.
> 

-- 
View this message in context:
http://www.nabble.com/Does-Hibernate-still-require-equals%28%29-and-hash
Code%28%29--tf3275322s2369.html#a9113546
Sent from the AppFuse - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-- 
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.441 / Virus Database: 268.18.3/698 - Release Date: 23.02.2007
04:39
 

-- 
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.441 / Virus Database: 268.18.3/698 - Release Date: 23.02.2007
04:39
 

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to