7

Is it possible to make the default Eclipse "Generate hashCode() and equals()" use getters instead of field references? - ie. can I get at the template that it uses?

I'm using Hibernate, and Proxied Objects are only LazyLoaded when getters are used and not from field references. It's an annoyance to be constantly changing it.

The obvious workarounds are to create a template myself or write a plugin - which feels like overkill.

EDIT: Looks like these aren't configurable. I'll pose this as a question for the JBoss Tools Group (They make some plugins for Hibernate).

Yuval Adam
  • 161,610
  • 92
  • 305
  • 395
Damo
  • 11,410
  • 5
  • 57
  • 74

3 Answers3

7

It's not a solution, rather workaround - but you might try generate equals(), then use 'encapsulate field' refactoring to replace all field acceses to use getters/setters (it works inside class also).

jb.
  • 23,300
  • 18
  • 98
  • 136
  • This works! Thanks. It changes all access to the field in the class but does so in a reasonable way. Also you have to do each field individually. Better than any other current solution though. – Damo May 05 '09 at 16:26
1

Ohhhh, be carefull with proxing : http://blog.xebia.com/2008/03/08/advanced-hibernate-proxy-pitfalls/ ;)

Esteve Camps
  • 1,113
  • 1
  • 10
  • 20
  • That's the article that got me started with this in the first place. The recommendation for pitfall #1 is to use getters. – Damo May 07 '09 at 16:16
0

I used a plugin to generate hashCode() and equals() with apache commons lang

kingoleg
  • 1,305
  • 15
  • 24
  • Linking a google search is not very useful. The results are probably very different now from 5 years ago. Do you have a link to the specific plugin you used? – finnw Aug 25 '14 at 14:50