gpt4 book ai didi

java - com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException : Unknown column 'productId3' in 'where clause'

转载 作者:行者123 更新时间:2023-12-01 15:19:56 26 4
gpt4 key购买 nike

尝试运行此查询时,出现错误com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:“where 子句”中的未知列“productId3”:

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

最佳答案

使用此查询:

select p.vendorId from Product p where p.productId3 = :id

关于java - com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException : Unknown column 'productId3' in 'where clause' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11080488/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com