3

Eclipse 的 Hibernate Tools 插件(版本 3.2.4)

大家好,
我正在使用该插件从我的 DB-Schema 对我的 POJO 和 DAO 进行逆向工程,并且由于某种原因,在 POJO 中没有创建 toString、equals 和 hashcode 方法。
我正在做的事情如下: 创建一个新的 JPA 项目。
配置它的 persistence.xml 文件如下:

<persistence-unit name="PU">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="hibernate.connection.driver_class" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"/>
<property name="hibernate.connection.password" value="pass"/>
<property name="hibernate.connection.url" value="jdbc:sqlserver://****:1433;DatabaseName=myDB"/>
<property name="hibernate.connection.username" value="user"/>
<property name="hibernate.default_catalog" value="myDB"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.SQLServerDialect"/>
<property name="hibernate.connection.schema" value="dbo"/>

<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.format_sql" value="false"/>

创建了一个 hibernate.reveng.xml 文件以仅在我的目录中选择我的 dbo scehma。
然后创建一个类型为 JPA 的 Hibernate 控制台配置,并从 JPA 配置中获取连接,最后配置持久性单元。
使用 Hibernate Code Generation 配置创建一个新配置,其中我启用了“从 JDBC 连接反向工程”定义了输出目录、包和 reveng 文件。
此外,我检查了该选项卡中的所有复选框(使用自定义模板除外)。
在我使用的导出器选项卡中:
1. 使用 Java 5 语法。
2. 生成 EJB3 注释。
并使用“域代码”和“DAO 代码”导出器。
这很好用(在解决了 DTP 插件兼容性的一些问题之后)。
主要问题是我在 Pojo.ftl 中看到以下表达式:

<#include "PojoToString.ftl"/>
<#include "PojoEqualsHashcode.ftl"/>

在 PojoToString.ftl 我看到:

<#if pojo.needsToString()> 

我在哪里可以设置这个属性?我希望我所有的 pojo 都需要 toString、equals 和 hashcode?

先感谢您

4

1 回答 1

2

这假定默认的 Hibernate 工具/JBoss 工具

您可以使用要调用 toString() 或 equals() 的每一列来定义它。将其作为属性提供

<table schema="public" name="someName" class="com.stackovervlow">
        <primary-key>

        </primary-key>
        <column name="xx" property="id" type="long">
            <meta attribute="use-in-tostring">true</meta>
            <meta attribute="scope-set">private</meta>
        </column>
        <column name="yy">
            <meta attribute="use-in-tostring">true</meta>
            <meta attribute="use-in-equals">true</meta>
        </column>   
    </table>
于 2012-08-02T13:10:28.753 回答