forge / plugin-hibernate-tools

Database Reverse Engineering with Hibernate Tools
19 stars 10 forks source link

Hash/Equals & toString() methods not generated #14

Open hanynowsky opened 12 years ago

hanynowsky commented 12 years ago

This is likely an enhancement ticket.

Hibernate-tools plugin for Forge, does not generate Equals/HashCOde & toString methods when generating entities.

maxandersen commented 12 years ago

Equals/hashcode can't be done differently automatically - see https://community.jboss.org/wiki/EqualsAndHashCode

Tostring is similar - what properties should be used which will nit have a performance penalty nor trigger recursive to string and actually be useful?

Sent from a mobile device

On 01/11/2012, at 02.13, Hanynowsky notifications@github.com wrote:

This is likely an enhancement ticket.

Hibernate-tools plugin for Forge, does not generate Equals/HashCOde & toString methods when generating entities.

— Reply to this email directly or view it on GitHub.

hanynowsky commented 12 years ago

Indeed, the question about Equals/Hashcode is still not fully answered when it comes to any system using ORM. Tweaking these methodes (Natural PK, Business P, UUID abstraction...) is necessary and it requires human intervention. However, as achieved by some scaffold tools in JPA world, generated entities contain Equals/hashcode/toString methods:at' equals() & toString() based on a fake business PK (id + someother property). hashcode based only on the id. These methods are commented in the generated code; so that the developer uncomment them and tweak them. That's it. I also understand that it might be better to use Eclipse or JBoss Developer to insert cutomized equals/hashcode/toString methods (SOURCE -> INSERT METHOD...) for entities of concern. If that's the case; It would appreciated if one mentions these steps as WARNING in HIbernate-Tools plugin documentation and as a comment in the generated entities.

maxandersen commented 12 years ago

If hashcode and equals is based off different attributes they are breaking the contract.

Note, forge plugin could pass a reveng.xml or class to hibernate tools and customize which fields are used when/where.

Sent from a mobile device

On 01/11/2012, at 19.15, Hanynowsky notifications@github.com wrote:

Indeed, the question about Equals/Hashcode is still not fully answered when it comes to any system using ORM. Tweaking these methodes (Natural PK, Business P, UUID abstraction...) is necessary and it requires human intervention. However, as achieved by some scaffold tools in JPA world, generated entities contain Equals/hashcode/toString methods:at' equals() & toString() based on a fake business PK (id + someother property). hashcode based only on the id. These methods are commented in the generated code; so that the developer uncomment them and tweak them. That's it. I also understand that it might be better to use Eclipse or JBoss Developer to insert cutomized equals/hashcode/toString methods (SOURCE -> INSERT METHOD...) for entities of concern. If that's the case; It would appreciated if one mentions these steps as WARNING in HIbernate-Tools plugin documentation and as a comment in the generated entities.

— Reply to this email directly or view it on GitHub.

hanynowsky commented 12 years ago

Sure. And hence comes the need to customize each Entity Pojo. The idea that Forge plugin could pass a smart class for guessing fields to use and how, is indeed the dream to come true.

maxandersen commented 12 years ago

Well, this is all doable - but what would you use for guessing ? :)

hanynowsky commented 11 years ago

Well that's the core of the job :) I wish I could tell you so easily. Basically, a surogate id if any with some other field (Guessing a business field is impossible - has to be done manually by the user). Priority given to the next unique field.