hibernate tools toString and equals method generation

1.1k views Asked by At

Below is my hibernate mapping file i want to generate toString and equals method using hibernate tool ant task.

<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>

but i am not able to generate toString or equals method is there any thing wrong in this mapping file.

i have checked hibernate-mapping-3.0.dtd and hibernate-reverse-engineering-3.0.dtd files both are up to date.

Best Regards,
Vivek S. Shah

1

There are 1 answers

0
Sunil Kumar On

It could be because you missed name="country" property at class level.

I have verified in hibernate 4,by adding meta data in the hiernate mapping file,equals and hashcode methods are creating as expected.

<?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>

You can also define these meta data at property level.

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