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:check this photo
codedesignation

SELECT * FROM Project p JOIN ProjectHasChief phc ON (p.id = phc.idproject)
JOIN Chief c ON (c.id = phc.id_chief)
WHERE c.id = (myID)
AND (designation LIKE '%user_string%' OR code LIKE '%user_string%');

And since I'm using hibernate I used Criteria:

Criteria c = session.createCriteria(ProjectHasChief.class);
            c.add(Restrictions.eq("chief", chief))
             .add(Restrictions.disjunction()
                    .add(Restrictions.like("project.designation", reg, MatchMode.ANYWHERE))
                    .add(Restrictions.like("project.code", reg, MatchMode.ANYWHERE)));
List<ProjectHasChief> list = (List<ProjectHasChief>)c.list();

But I get this error:

org.hibernate.QueryException: could not resolve property: project.designation of: smt.agm.entities.ProjectHasChief

Project unit :

@Entity
@Table(name="projet")
public class Project {

    @Id 
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", columnDefinition="serial")
    private int id;

    @Column(name="code")
    private String code;

    @Column(name="designation")
    private String designation;

    @OneToMany(cascade = CascadeType.ALL, mappedBy="project", orphanRemoval=true)
    @OrderBy(clause="id DESC")
    private List<ProjectHasChief> chiefs = new ArrayList<ProjectHasChief>();
}

Chief Entity:

@Entity
@Table(name="chief")
public class Chief {

    @Id 
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", columnDefinition="serial")
    private int id;

    @Column(name = "name")
    private String name;
}

ProjectHasChief entity:

@Entity
@Table(name="mapping_chantier_chef")
public class ProjectHasChief {
    @Id 
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", columnDefinition="serial")
    private int id;

    @ManyToOne
    private Project project;

    @ManyToOne
    private Chief chief;

    @Column(name="date_deb")
    private Date startDate;

    @Column(name="date_fin")
    private Date endDate;
}

WHE hibernate doesn't know properties designationof Projectentities? !

Rorschach

Are you absolutely sure that all mappings and joins are working correctly?

If so, you can try declaring an implicit alias for Project like this:

Criteria c = session.createCriteria(ProjectHasChief.class);
        c.createAlias("project", "project") //THIS ONE
        c.add(Restrictions.eq("chief", chief))
        c.add(Restrictions.disjunction()
                .add(Restrictions.like("project.designation", reg, MatchMode.ANYWHERE))
                .add(Restrictions.like("project.code", reg, MatchMode.ANYWHERE)));

List<ProjectHasChief> list = (List<ProjectHasChief>)c.list();

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

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

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

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

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: 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

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