Hi,
I need to write composite-id for a view.
The view itself dose not contain any column that could be used for element ID in the hibernate-mapping. Thus, I need to create a composite-id from 5 columns. The document from anywhere (online, books,...) about this topic is too little.
Here is my mapping:
<hibernate-mapping>
<class name="gain.site.server.persistence.InvLoc" table="XX_INV_LOCATION_V">
<composite-id name="invLocPK" class="gain.site.server.persistence.InvLocPK">
<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="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>
Here is my POJO:
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;
}
}
And the class for the composite id:
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 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
I got the exception:
org.hibernate.exception.SQLGrammarException: could not execute query
.....
Help, please HELP!
Thanks,
Gina
|