1 Reply Latest reply on May 5, 2009 5:45 AM by maxandersen

    equals() hashcode() generation feature request

    damianharvey

      Using the default Eclipse "Generate hashcode() and equals()" from the Source menu gives you these two methods but generated using fields rather than getters.

      As Hibernate uses Proxy objects and only loads the actual object when a getter is encountered, these generated methods can prove problematic (eg. when comparing two identical entities for equality and if one is a proxy generated by CGLIB then they will not be equal as the proxied entity is not loaded via field access).

      See here http://blog.xebia.com/2008/03/08/advanced-hibernate-proxy-pitfalls/ for an explanation.

      The Eclipse templates for this generation aren't accessible, so it would be handy if there was an option to create these methods with getters via the Hibernate Eclipse plugins that are part of the Jboss Tools.

      Thanks,

      Damian.

        • 1. Re: equals() hashcode() generation feature request
          maxandersen

          This is not the only thing that is wrong with the hashcode()/equals() in Eclipse - you should report it in Eclipse bugzilla (post the link to it here)

          Other things that are problematic in their implementation:

          They put collections in by default (it vary *rarely* is the right thing to do)

          No way to control ordering (have a big impact on performance)

          ....