Thanks Steve, Gavin for the reply!
I did not use <key-many-to-one>, here is my .hbm.xml file:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="com.hibernate.Coddsc" table="coddsc">
<jcs-cache usage="read-only"/>
<composite-id name="id" class="com.hibernate.CoddscKey">
<key-property name="cdty" column="cdty"/>
<key-property name="code" column="code"/>
</composite-id>
<property name="dddesc" column="dddesc"/>
<property name="ddstat" column="ddstat"/>
</class>
</hibernate-mapping>
<!-- parsed in 0ms -->
and also this is my CoddscKey java class:
Code:
package com.hibernate;
import java.io.Serializable;
public class CoddscKey implements Serializable{
private String cdty;
private String code;
public CoddscKey()
{
}
public CoddscKey(String cdty, String code) {
this.cdty = cdty;
this.code = code;
}
public CoddscKey(String cdty)
{
this.cdty = cdty;
this.code = null;
}
public String getCdty()
{
return cdty;
}
public void setCdty(String cdty)
{
this.cdty = cdty;
}
public String getCode()
{
return code;
}
public void setCode(String code)
{
this.code = code;
}
public boolean equals(Object other) {
CoddscKey that = (CoddscKey) other;
return this.cdty.equals(that.cdty) && this.code==that.code;
}
/**
* Returns the hash code for the key.
*/
public int hashCode() {
return (this.cdty.hashCode() + this.code.hashCode());
}
}
Any suggestions about the equals()/hashCode() function?
Thanks a lot!