-->
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.  [ 2 posts ] 
Author Message
 Post subject: Composite ID and SQLGrammarException
PostPosted: Wed Dec 12, 2007 5:21 pm 
Newbie

Joined: Wed Dec 12, 2007 2:30 pm
Posts: 3
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


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 13, 2007 7:50 am 
Beginner
Beginner

Joined: Tue Nov 27, 2007 9:44 am
Posts: 46
Hi

What is the code you execute when this exception occurs? Where in your code does the exception occur?

Have you set hibernate.show_sql to true? What is the generated SQL?

Regards,
Frank


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.