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));

Related


org.hibernate.QueryException: Cannot resolve property

TO: I have the following JPA class. /** * The persistent class for the ACCOUNT database table. * */ @Entity @Table(name="ACCOUNT") public class Account implements Serializable { private static final long serialVersionUID = 1L; @Id @XmlID @Column(name="ACC

org.hibernate.QueryException: Cannot resolve property: filename

Ankit Lamba: I am using Hibernate to get values Criteriafrom filenamea column of a table contaque_recording_log. but when i get the result it throws an exception org.hibernate.QueryException: Cannot resolve property: filename of com.contaque.hibernateTableMapp

org.hibernate.QueryException: Cannot resolve property

TO: I have the following JPA class. /** * The persistent class for the ACCOUNT database table. * */ @Entity @Table(name="ACCOUNT") public class Account implements Serializable { private static final long serialVersionUID = 1L; @Id @XmlID @Column(name="ACC

org.hibernate.QueryException: Cannot resolve property: filename

Ankit Lamba: I am using Hibernate to get values Criteriafrom filenamea column of a table contaque_recording_log. but when i get the result it throws an exception org.hibernate.QueryException: Cannot resolve property: filename of com.contaque.hibernateTableMapp

org.hibernate.QueryException: Cannot resolve property: filename

Ankit Lamba: I am using Hibernate to get values Criteriafrom filenamea column of a table contaque_recording_log. but when i get the result it throws an exception org.hibernate.QueryException: Cannot resolve property: filename of com.contaque.hibernateTableMapp

Hibernate QueryException: Cannot resolve property

SlimenTN So I have these relationships between these 3 tables. What I want to do is to search (by or ) and get a list of projects for a specific responsible person like this: codedesignation SELECT * FROM Project p JOIN ProjectHasChief phc ON (p.id = phc.idpro

org.hibernate.QueryException: Cannot resolve property

South Africa I have the following JPA class. /** * The persistent class for the ACCOUNT database table. * */ @Entity @Table(name="ACCOUNT") public class Account implements Serializable { private static final long serialVersionUID = 1L; @Id @XmlID @Column(

org.hibernate.QueryException: Cannot resolve property

Chen Yuhua I want to get the sum of a column in a table. public class PaymentLogDAO extends AbstractModel<PaymentLog> { public PaymentLogDAO() { super(PaymentLog.class); } public BigDecimal sum(String keyword) { try {

org.hibernate.QueryException: Cannot resolve property

TO: I have the following JPA class. /** * The persistent class for the ACCOUNT database table. * */ @Entity @Table(name="ACCOUNT") public class Account implements Serializable { private static final long serialVersionUID = 1L; @Id @XmlID @Column(name="ACC

org.hibernate.QueryException: Cannot resolve property: filename

Ankit Lamba: I am using Hibernate to get values Criteriafrom filenamea column of a table contaque_recording_log. but when i get the result it throws an exception org.hibernate.QueryException: Cannot resolve property: filename of com.contaque.hibernateTableMapp