Hibernate-org.hibernate.QueryException: Cannot resolve property:
Furquan Ahmed
I have a DocMovement class like this:
@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
}
The DocMaster class looks like this:
@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
}
When I try to run the following code:
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();
Then I get the following exception:
[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
In other cases I have tried to query with the criteria shown above and the query works fine, but in this case I cannot understand what I am doing wrong. I've also tried using eager fetch, I haven't used aliases before, so I've tried using aliases as well.
Please help me solve the problem!
username
Try adding an alias:
criteria.createAlias("documentMovement.docMaster", "docMaster")
then call
criteria.add(Restrictions.ne("docMaster.status",FMSConstants.CLOSED_STATUS));