gpt4 book ai didi

java - hibernate - org.hibernate.QueryException : could not resolve property:

转载 作者:行者123 更新时间:2023-11-29 06:32:13 24 4
gpt4 key购买 nike

我有一个像这样的 DocMovement 类:

    @Entity
@Table(name = "DOC_MVMNT")
public class DocMovement {
@Id
@GeneratedValue
@Column(name = "MVMNT_ID")
private int mvmnt_id;

@ManyToOne
@JoinColumn(name = "BARCODE")
public DocMaster docMaster;
// other fields and getters setters
}

DocMaster 类是这样的:

@Entity 
@Table(name="DOC_MASTER")
public class DocMaster {
@Id
@NotNull
@Column(name = "BARCODE")
private String barcode;

@Column(name = "DOC_NO")
private String docNo ;

@Column(name="DOC_TYPE")
private String docType;

@Column(name="STATUS")
private String status;
// other fields and getters setters
}

当我尝试运行以下代码时:

Criteria criteria = session.createCriteria(DocMovement.class,"documentMovement");
criteria.add(Restrictions.eq("documentMovement.recipientDetail.empId", empId));
criteria.add(Restrictions.eq("documentMovement.isCurrent", true));
criteria.add(Restrictions.ne("documentMovement.docMaster.status",FMSConstants.CLOSED_STATUS));
criteria.add(Restrictions.ne("documentMovement.docMaster.status",FMSConstants.DISPOSED_STATUS));
List<DocMovement> documentsHeld = (List<DocMovement>) criteria.list();

然后我得到以下异常:

 [org.hibernate.QueryException: could not resolve property:
docMaster.status of: com.fms.persistence.DocMovement] with root cause
org.hibernate.QueryException: could not resolve property:
docMaster.status of: com.fms.persistence.DocMovement

在其他情况下,我尝试使用如上所示的条件进行查询,查询运行良好,但我无法理解在这种情况下我做错了什么。我也尝试过使用 eager fetch,之前我没有使用别名,所以我也尝试使用别名。

请帮我解决问题!!!

最佳答案

尝试添加别名:

criteria.createAlias("documentMovement.docMaster", "docMaster")

稍后调用

 criteria.add(Restrictions.ne("docMaster.status",FMSConstants.CLOSED_STATUS));

关于java - hibernate - org.hibernate.QueryException : could not resolve property:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30831013/

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