Hibernate 使用 Equals 生成 POJO
我们在一个新项目中使用 hibernate,然后使用 hibernate.reveng.xml
创建 *.hbm.xml
文件和 POJO。我们希望在每个 POJO 中都有 equals 方法。 我发现您可以在 hbm 文件中使用 true
来标记在 equals 中使用哪些属性。但这意味着编辑大量文件,然后在将来如果/当我们修改数据库中的表或列时再次重新编辑文件。
所以我想知道是否有一种方法可以在 hibernate.reveng.xml
文件中的每个 pojo(table) 的 equals 方法中放置要使用的属性?
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.
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是一个未记录的功能(在线 DTD 已过时)但您可以在
和
元素中添加。换句话说,您应该能够执行以下操作:
hibernate-tools.jar 中的 DTD 应该是最新的(并且看起来像 这个)并声明:
有 Seam in Action 论坛中对此的讨论。
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:The DTD in hibernate-tools.jar should be up-to-date (and looks like this one) and declare:
There is a discussion about this in the Seam in Action forums.
eclipse 有 equal 和 hash 代码生成器。我们用它来生成这些方法。
eclipse has equal and hash code generator. We use that for generation of those methods.