【问题标题】:hibernate tools toString and equals method generationhibernate 工具 toString 和 equals 方法生成
【发布时间】:2012-02-17 13:47:50
【问题描述】:

下面是我想生成 toString 和 equals 方法的休眠映射文件 休眠工具蚂蚁任务。

<class name="org.hibernate.db.Country" table="country" catalog="world">
    <meta attribute="use-in-tostring">true</meta>
    <meta attribute="use-in-equals">true</meta>
    <id name="code" type="string">
        <column name="Code" length="3" />
        <generator class="assigned" />
    </id>      
</class>

但我无法生成 toString 或 equals 方法,这个映射文件有什么问题吗?

我检查了 hibernate-mapping-3.0.dtd 和 hibernate-reverse-engineering-3.0.dtd 文件都是最新的。

最好的问候,
Vivek S. Shah

【问题讨论】:

标签: hibernate code-generation reverse-engineering hibernate-tools


【解决方案1】:

这可能是因为您错过了类级别的 name="country" 属性。

我已经在 hibernate 4 中验证,通过在 hiernate 映射文件中添加元数据,equals 和 hashcode 方法按预期创建。

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
    <class entity-name="com.hrdb.Employee" name="Employee" table="EMPLOYEE" schema="PUBLIC">
        <meta attribute="use-in-tostring">true</meta>
        <meta attribute="use-in-equals">true</meta>
        <id name="eid" type="integer">
            <column name="EID" length="255" not-null="true" precision="19"/>
            <generator class="identity"/>
        </id>
        <property name="firstname" type="string">
            <column name="FIRSTNAME" length="255" not-null="false" precision="19"/>
        </property>

您还可以在属性级别定义这些元数据。

<property name="name" type="string">
      <meta attribute="use-in-tostring">true</meta>
      <meta attribute="use-in-equals">true</meta>      
</property>

【讨论】:

    猜你喜欢
    • 2011-06-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多