Hibernate generates POJOs with equal

We use hibernate in a new project, where we use hibernate.reveng.xml to create our *.hbm.xml files and POJO after that. We want to have equal methods in each of our POJOs. I found that you can use <meta attribute="use-in-equals">true</meta> in your hbm files to mark which properties to use as equal. But this would mean editing a large number of files, and then re-editing the files in the future if / when we modify tables or columns in our database.

So, I was wondering if there is a way to place which properties to use in the equals method for each pojo (table) in the hibernate.reveng.xml file?

+4
source share
2 answers

This is an undocumented feature (and online DTD is deprecated), but you can add <meta> to <table> and <colum> . In other words, you have to do this:

 <table name="PROPERTY" catalog="DATA" schema="PUBLIC"> <meta attribute="extends">BasicDataObject</meta> <meta attribute="scope-class">public abstract</meta> <column name="ID"> <meta attribute="use-in-equals">true</meta> <meta attribute="use-in-tostring">true</meta> </column> </table> 

The DTD in hibernate-tools.jar should be updated (and looks like this one ) and declare:

 <!ELEMENT column (meta*) > 

discussion about this on the Seam in Action forums.

+6
source

eclipse has the same and hash code. We use this to generate these methods.

+2
source

Source: https://habr.com/ru/post/1305220/


All Articles