0

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

user674961
  • 51
  • 10
  • hmm, one year ago someone had the same problem - without answer :/ http://stackoverflow.com/questions/4945160/how-to-get-hibernate-tools-to-generate-pojos-with-tostring-equals-and-hashcode – Christian Jan 25 '12 at 08:22
  • Maybe this thread helps? http://stackoverflow.com/questions/2523826/hibernate-generate-pojos-with-equals – Christian Jan 25 '12 at 08:23

1 Answers1

0

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>
Sunil Kumar
  • 5,477
  • 4
  • 31
  • 38