Hibernate使用Equals生成POJO [英] Hibernate generate POJOs with Equals

查看:123
本文介绍了Hibernate使用Equals生成POJO的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在使用 hibernate.reveng.xml 创建我们的 *。hbm.xml 文件和POJO。我们希望在每个POJO中都有平等的方法。
我发现您可以在您的hbm文件中使用< meta attribute =use-in-equals> true< / meta> 来标记哪些属性在平等中使用。但是这意味着要编辑大量文件,并且在我们修改我们数据库中的表或列时将来再次重新编辑这些文件。

We are using hibernate in a new project where we use the hibernate.reveng.xml to create our *.hbm.xml files and POJOs after that. We want to have equals 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 in the equals. But this would mean editing alot of files, and then re-editing the files again in the future if/when we modify tables or columns in our DB.

所以我想知道是否有一种方法可以在 hibernate.reveng.xml file?

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?

推荐答案

这是一个未记录的功能和在线 DTD 已过期),但您可以添加<$ < table> < colum> 中的c $ c>< meta> c>元素。换句话说,您应该可以这样做:

This is an undocumented feature (and the online DTD is out of date) but you can add <meta> in the <table> and <colum> elements. In other words, you should be able 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>

hibernate-tools.jar 中的DTD应该是最新的,日期(并且看起来像这一个)并声明:

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

<!ELEMENT column (meta*) >

讨论关于Seam in Action论坛。

There is a discussion about this in the Seam in Action forums.

这篇关于Hibernate使用Equals生成POJO的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆