views:

540

answers:

4

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).

A: 

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

kingoleg
A: 

Oddly, these templates don't seem to be configurable at all.

You might want to look at this question. Also this blog. Google will probably get you lots more.

Moss Prescott
Thanks but I'd already read that comment and everything that Google was willing to proffer. Commons4E doesn't use getters either.
Damo
+1  A: 

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
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
A: 

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

Esteve Camps
That's the article that got me started with this in the first place. The recommendation for pitfall #1 is to use getters.
Damo