hbm2java does not generate equals/hashCode for composite-id

Description

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
the list of jar files is attached

Ant build script:

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

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

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:

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.

Environment

Hibernate 3.1.3, Sybase database, Windows platform

Attachments

1

Activity

Show:

Koen AersApril 28, 2016 at 4:30 PM

I am closing this issue with "Out of Date" resolution since there hasn't been any activity on it since May 28th 2006. Please feel free to reopen it if you think we can still do something about this.

Max Rydahl AndersenMay 28, 2006 at 6:45 PM

i can reproduce this via ant, but are you 100% you are not using reverse engineering in the eclipse plugin instead of the hbm.xml as you show here ? (reveng is namely automatically injecting the proper meta attributes into the composite id, where as the hbm.xml dumping does not include the meta attributes)

btw. the fix is a bit hard to implement since the pojo generator must be told if a component is actually a composite-id; at the moment it does not know.

...and i'm not sure i want to do that instead of adding <meta> support to the hbmxml exporter.

Out of Date

Details

Assignee

Reporter

Bug Testcase Reminder (view)

Bug reports should generally be accompanied by a test case!

Bug Testcase Reminder (edit)

Bug reports should generally be accompanied by a test case!

Participants

Andrey Myatlyuk
Koen Aers
Max Rydahl Andersen

Components

Affects versions

Priority

Created May 25, 2006 at 4:04 PM
Updated April 28, 2016 at 4:30 PM
Resolved April 28, 2016 at 4:30 PM