View Single Post
  #12 (permalink)  
Old 01-03-2008, 04:21 AM
gina.nguyen gina.nguyen is offline
Member
 
Join Date: Jan 2008
Posts: 1
gina.nguyen is on a distinguished road
that document seems not very clear...
Hi,

I "google" the "composite id" and one of the link is that document. After reading it, I implemented my composite id as the primary key of a table (there is only 1 table). The rows in the table are identified uniquely by 5 columns of type varchar2 (or String in Java). Here is my implementation:

<?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 Oct 17, 2007 4:12:40 PM by Hibernate Tools 3.2.0.b9 -->
<hibernate-mapping>

<class name="gain.site.server.persistence.InvLoc" table="XX_INV_LOCATION_V">
<composite-id name="invLocPK" class="gain.site.server.persistence.InvLocPK" mapped="true">
<key-property name="supPartNum" column="ITEM_NUMBER" type="string" length="10" mapped="true" />
<key-property name="partSN" column="SERIAL_NUMBER" type="string" length="10" mapped="true" />
<key-property name="suppCode" column="SUPPLIER_CODE" type="string" length="10" mapped="true" />
<key-property name="custRefID" column="CUST_REF_ID" type="string" length="10" mapped="true" />
<key-property name="locCode" column="LOCATION_NAME" type="string" length="10" mapped="true" />
</composite-id>
<property name="supPartNum" type="string">
<column name="ITEM_NUMBER" length="10" />
</property>
<property name="partSN" type="string">
<column name="SERIAL_NUMBER" length="10" />
</property>
<property name="suppCode" type="string">
<column name="SUPPLIER_CODE" length="10" />
</property>
<property name="custRefID" type="string">
<column name="CUST_REF_ID" length="10" />
</property>
<property name="locCode" type="string">
<column name="LOCATION_NAME" length="10" />
</property>


<property name="quantity" type="integer">
<column name="QUANTITY" precision="22" scale="0" />
</property>
<property name="UOM" type="string">
<column name="UNIT_OF_MEASURE_CODE" length="10" />
</property>
</class>

</hibernate-mapping>

public class InvLocPK implements Serializable {
/**
*
*/
private static final long serialVersionUID = 9L;
private String supPartNum;
private String partSN;
private String suppCode;
private String custRefID;
private String locCode;

public InvLocPK() {
}

public InvLocPK(InvLocPK invLocPK) {
this.suppCode = invLocPK.suppCode;
this.partSN = invLocPK.partSN;
this.locCode = invLocPK.locCode;
this.custRefID = invLocPK.custRefID;
this.supPartNum = invLocPK.supPartNum;
}

public boolean equals(InvLocPK invLocPK) {
return (this.custRefID.equals(invLocPK.custRefID) &&
this.locCode.equals(invLocPK.locCode) &&
this.partSN.equals(invLocPK.partSN) &&
this.supPartNum.equals(invLocPK.supPartNum) &&
this.suppCode.equals(invLocPK.suppCode));
}

public boolean equals(Object obj) {
if(this == obj)
return true;
if((obj == null) || (obj.getClass() != this.getClass()))
return false;
// object must be Test at this point
InvLocPK invLocPK = (InvLocPK)obj;
return (this.custRefID.equals(invLocPK.custRefID) &&
this.locCode.equals(invLocPK.locCode) &&
this.partSN.equals(invLocPK.partSN) &&
this.supPartNum.equals(invLocPK.supPartNum) &&
this.suppCode.equals(invLocPK.suppCode));
}

public int hashCode () {
return new HashCodeBuilder().
append(getSuppCode()).
append(getPartSN()).
append(getSupPartNum()).
append(getLocCode()).
append(getCustRefID()).
toHashCode();
}

public String getSupPartNum() {
return supPartNum;
// return "A-1";
}

public void setSupPartNum(String supPartNum) {
this.supPartNum = supPartNum;
}

public String getPartSN() {
return partSN;
// return "501";
}

public void setPartSN(String partSN) {
this.partSN = partSN;
}

public String getSuppCode() {
return suppCode;
// return "C11111";
}

public void setSuppCode(String suppCode) {
this.suppCode = suppCode;
}

public String getCustRefID() {
return custRefID;
// return "GCSRT";
}

public void setCustRefID(String custRefID) {
this.custRefID = custRefID;
}

public String getLocCode() {
return locCode;
// return "W101";
}

public void setLocCode(String locCode) {
this.locCode = locCode;
}

} // end of InvLocPK class


public class InvLoc {
private InvLocPK invLocPK;
private int quantity;
private String UOM;

public InvLoc() {
invLocPK = new InvLocPK();
}

public String getSupPartNum() {
return this.invLocPK.getSupPartNum();
// return "A-1";
}

public void setSupPartNum(String supPartNum) {
this.invLocPK.setSupPartNum(supPartNum);
}

public String getPartSN() {
return this.invLocPK.getPartSN();
// return "501";
}

public void setPartSN(String partSN) {
this.invLocPK.setPartSN(partSN);
}

public String getSuppCode() {
return this.invLocPK.getSuppCode();
// return "C11111";
}

public void setSuppCode(String suppCode) {
this.invLocPK.setSuppCode(suppCode);
}

public String getCustRefID() {
return this.invLocPK.getCustRefID();
// return "GCSRT";
}

public void setCustRefID(String custRefID) {
this.invLocPK.setCustRefID(custRefID);
}

public String getLocCode() {
return this.invLocPK.getLocCode();
// return "W101";
}

public void setLocCode(String locCode) {
this.invLocPK.setLocCode(locCode);
}

public InvLocPK getInvLocPK() {
return invLocPK;
}

public void setInvLocPK(InvLocPK invLocPK) {
this.invLocPK = invLocPK;
}

public int getQuantity() {
return quantity;
// return 1;
}

public void setQuantity(int quantity) {
this.quantity = quantity;
}

public String getUOM() {
return UOM;
// return "EA";
}

public void setUOM(String uom) {
UOM = uom;
}

}

I got mapping exception. What could be wrong with my implementation?

Thanks,
Gina
Reply With Quote