試圖運行此查詢時,我得到一個錯誤com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'productId3' in 'where clause'
:com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:未知列「productId3」在「where子句」
public Vendor getVendorId(ProductInfo productInfo) {
return (Vendor) this.sessionFactory
.getCurrentSession()
.createQuery(
"select vendorId from Product where productId3 = :id")
.setParameter("id", productInfo).uniqueResult();
}
類產品看起來是這樣的:
@Entity
@Table(name="PRODUCT")
public class Product{
@Id
@GeneratedValue
@Column(name="PRODUCT_ID2")
private Integer productId2;
public void setProductId2(Integer productId2){
this.productId2 = productId2;
}
public Integer getProductId2(){
return productId2;
}
@ManyToOne(cascade=CascadeType.ALL)
@JoinColumn(name="PRODUCT_ID3")
private ProductInfo productId3;
public void setProductId3(ProductInfo productId3){
this.productId3 = productId3;
}
public ProductInfo getProductId3(){
return productId3;
}
@ManyToOne(cascade=CascadeType.ALL)
@JoinColumn(name="VENDOR_ID")
private Vendor vendorId;
public void setVendorId(Vendor vendorId){
this.vendorId = vendorId;
}
public Vendor getVendorId(){
return vendorId;
}
@OneToMany(mappedBy="productId2")
private Set<ProductRevision> productRevisions;
public void setProductRevisions(Set<ProductRevision> productRevisions){
this.productRevisions = productRevisions;
}
public Set<ProductRevision> getProductRevisions(){
return productRevisions;
}
}
爲什麼我得到這個錯誤?我不明白爲什麼它找不到名稱完全相同的列。謝謝你的幫助!
/d
您可以通過將showSql參數設置爲1並檢查輸出查詢並在此處發佈來開始。 – MahdeTo