-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 10 posts ] 
Author Message
 Post subject: hbm2java does not generate equals/hashCode for composite-id
PostPosted: Wed May 24, 2006 3:04 pm 
Newbie

Joined: Mon Jan 30, 2006 3:40 pm
Posts: 6
Location: New York, NY
Hi!

I'm using Hibernate Tools 3.1.0.beta5

If I use the tools as plug-in for eclipse, it works perfect. All hashCode and equals methods are generated automatically. But if I use Ant task to do the same, no hashCode or equals method are generated. If I use meta attibutes in mapping, then method is implemented, but I have too many composite id to generate, so I'd like hbm2java generate them for me. As it suppose to do.

hibernate.cfg.xml
and mappings are the same

Ant build script:
Code:
    <path id="library.hibernatetools.classpath">
      <fileset dir="C:/dev/hibernate/hibernatetools-3.1.0.beta5/lib">
         <include name="*.jar"/>
      </fileset>
   </path>

    <taskdef name="hibernatetool"
        classname="org.hibernate.tool.ant.HibernateToolTask"
        classpathref="library.hibernatetools.classpath"/>

   <target name="hbm2java">
        <hibernatetool destdir="${module.jstl.basedir}/src">
            <classpath>
                <path location="${module.jstl.basedir}/src"/>
            </classpath>
            <configuration configurationfile="${module.jstl.basedir}/src/hibernate.cfg.xml"/>
            <hbm2java/>
        </hibernatetool>
   </target>


Mapping:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated May 22, 2006 3:18:01 PM by Hibernate Tools 3.1.0.beta5 -->
<hibernate-mapping>
    <class name="model.ResponseNote" table="ECB_NOTES_RESP" schema="dbo" catalog="recon_dev">
        <composite-id name="id" class="model.ResponseNoteId">
            <key-property name="ecbResponseId" type="long">
                <column name="ECB_RESPONSE_ID" precision="15" scale="0" />
            </key-property>
            <key-property name="ecbEligibilityId" type="int">
                <column name="ECB_ELIGIBILITY_ID" />
            </key-property>
            <key-property name="ecbNotesId" type="int">
                <column name="ECB_NOTES_ID" />
            </key-property>
        </composite-id>
        <property name="notes" type="string">
            <column name="NOTES" length="264" />
        </property>
    </class>
</hibernate-mapping>


Generated java with Ant task:
Code:
package model;
// Generated May 24, 2006 2:51:40 PM by Hibernate Tools 3.1.0.beta5

/**
* ResponseNoteId generated by hbm2java
*/
public class ResponseNoteId  implements java.io.Serializable {

    // Fields   

     private long ecbResponseId;
     private int ecbEligibilityId;
     private int ecbNotesId;

     // Constructors

    /** default constructor */
    public ResponseNoteId() {
    }

    /** full constructor */
    public ResponseNoteId(long ecbResponseId, int ecbEligibilityId, int ecbNotesId) {
       this.ecbResponseId = ecbResponseId;
       this.ecbEligibilityId = ecbEligibilityId;
       this.ecbNotesId = ecbNotesId;
    }
   
   
    // Property accessors
    public long getEcbResponseId() {
        return this.ecbResponseId;
    }
   
    public void setEcbResponseId(long ecbResponseId) {
        this.ecbResponseId = ecbResponseId;
    }
    public int getEcbEligibilityId() {
        return this.ecbEligibilityId;
    }
   
    public void setEcbEligibilityId(int ecbEligibilityId) {
        this.ecbEligibilityId = ecbEligibilityId;
    }
    public int getEcbNotesId() {
        return this.ecbNotesId;
    }
   
    public void setEcbNotesId(int ecbNotesId) {
        this.ecbNotesId = ecbNotesId;
    }

}



Generated java within Eclipse:
Code:
package model;

// Generated May 24, 2006 11:43:19 AM by Hibernate Tools 3.1.0.beta5

/**
* EcbNotesRespId generated by hbm2java
*/
public class EcbNotesRespId implements java.io.Serializable {

   // Fields   

   private long ecbResponseId;

   private int ecbEligibilityId;

   private int ecbNotesId;

   // Constructors

   /** default constructor */
   public EcbNotesRespId() {
   }

   /** full constructor */
   public EcbNotesRespId(long ecbResponseId, int ecbEligibilityId,
         int ecbNotesId) {
      this.ecbResponseId = ecbResponseId;
      this.ecbEligibilityId = ecbEligibilityId;
      this.ecbNotesId = ecbNotesId;
   }

   // Property accessors
   public long getEcbResponseId() {
      return this.ecbResponseId;
   }

   public void setEcbResponseId(long ecbResponseId) {
      this.ecbResponseId = ecbResponseId;
   }

   public int getEcbEligibilityId() {
      return this.ecbEligibilityId;
   }

   public void setEcbEligibilityId(int ecbEligibilityId) {
      this.ecbEligibilityId = ecbEligibilityId;
   }

   public int getEcbNotesId() {
      return this.ecbNotesId;
   }

   public void setEcbNotesId(int ecbNotesId) {
      this.ecbNotesId = ecbNotesId;
   }

   public boolean equals(Object other) {
      if ((this == other))
         return true;
      if ((other == null))
         return false;
      if (!(other instanceof EcbNotesRespId))
         return false;
      EcbNotesRespId castOther = (EcbNotesRespId) other;

      return (this.getEcbResponseId() == castOther.getEcbResponseId())
            && (this.getEcbEligibilityId() == castOther
                  .getEcbEligibilityId())
            && (this.getEcbNotesId() == castOther.getEcbNotesId());
   }

   public int hashCode() {
      int result = 17;

      result = 37 * result + (int) this.getEcbResponseId();
      result = 37 * result + this.getEcbEligibilityId();
      result = 37 * result + this.getEcbNotesId();
      return result;
   }

}



With all this code with Ant task I get ResponseNoteId java file without equals or hashCode methods. While within Eclipse, using the same code I get equals and hashCode implemented.

What am I missing here?

Andrey


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 25, 2006 5:15 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
that should definitly not happen since it is the exact same code that is running there .... put it in jira and i'll have a look.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 25, 2006 10:09 am 
Newbie

Joined: Mon Jan 30, 2006 3:40 pm
Posts: 6
Location: New York, NY
Posted to jira. Let me know if I can help with anything.

Thank you!

Andrey


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 27, 2006 4:51 pm 
Newbie

Joined: Wed May 24, 2006 5:45 pm
Posts: 1
Try following

Put
<meta attribute="use-in-equals">true</meta>

inside the
<key-property> tag as you have added the <column>

This worked for me

Thanks & Regards
Shirish Joshi


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 28, 2006 2:50 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
Hi shirishrj,

He knows about this, composite id's should though have equals/hashcode generated automatically independent of meta attributs.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 29, 2006 7:52 am 
Newbie

Joined: Wed Jun 28, 2006 11:04 am
Posts: 4
I have the same problem, any news whether there is already a fix/solution for this issue and where to get it ?
(adding the meta attribute is not realy an option for me)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 30, 2006 5:15 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
i don't recall any reporting this in jira so i don't have something to work with. do that (or point me to an existing jira that i might have forgotten) and i'll look at it.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 30, 2006 5:51 am 
Newbie

Joined: Wed Jun 28, 2006 11:04 am
Posts: 4
ok
i checked, there is no open issue for this one so I opend a new one:
HBX-696

hope it's ok that way.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 30, 2006 10:12 am 
Newbie

Joined: Fri Jun 09, 2006 7:22 am
Posts: 8
I had the same experience: ant won't generate equals() and hashsCode() but eclipse will.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 16, 2007 2:26 pm 
Newbie

Joined: Mon Apr 16, 2007 2:05 pm
Posts: 5
You find an excellent solution shirishrj. It’s simple and elegant.

_________________
search engine placement


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 10 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.