0

下面是我想使用休眠工具 ant 任务生成 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

4

1 回答 1

0

这可能是因为您错过了类级别的 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>
于 2015-07-14T13:53:37.140 回答