我有一个类DocMovement这样的:休眠 - org.hibernate.QueryException:无法解析属性:
@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,之前我没有使用别名,所以我尝试使用别名。
请帮我解决问题!!!
这工作,Thanx洛特,但我不明白为什么,因为我没有按照你在其他情况下建议,但它工作正常。为什么在这种情况下,我不得不给别名。 –