0

I'm trying get all data from isssue table that matches with projectname and Issue Id. I'm getting following error. please help me.

Tables Project ProjectID ProjectName

Issue issueID identifier sourceStatus title severity description

Project.java

@Entity
    @Table(name="project")
    public class Project implements Serializable {

        private static final long serialVersionUID = 2457316470957669814L;
        @Id
        @GeneratedValue(strategy=GenerationType.AUTO)
        @Column(name="ProjectId")
        private Integer projectId;

        @Column(name="projectname")
        private String projectName;

        @OneToMany(fetch=FetchType.EAGER,cascade=CascadeType.ALL,mappedBy = "project")
        private List<Issue> issue;

        //getters and setters
    }

Issue.java

@Entity
@Table(name="issue")
public class Issue implements Serializable{

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    @Column(name="Id")
    private Integer Id;

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

    @Column(name="sourcestatus")
    private String sourceStatus;

    @Column(name="severity")
    private Integer severity;

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

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

    @ManyToOne
    @JoinColumn(name ="ProjectId")
    private Project project;

//getters and setters
  }

IssueDAOImpl.java

public List<Issue> getAllIssue(String identifier,String projectName) {
    Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Issue.class);
    criteria.createAlias("Project", "Prj");
    criteria.add(Restrictions.eq("identifier",identifier));
    criteria.add(Restrictions.eq("Prj.projectName",projectName));

    List<Issue> list=criteria.list();
    return list;
}

CONSOLE

SEVERE: Servlet.service() for servlet [dcm] in context with path [/SearchTool] threw exception [Request processing failed; nested exception is org.hibernate.QueryException: could not resolve property: Project of: com.dcm.search.bean.Issue] with root cause
org.hibernate.QueryException: could not resolve property: Project of: com.dcm.search.bean.Issue
2
  • Please can you post the contents of the ArchivalIssue class? Commented Aug 1, 2014 at 13:13
  • @Hedley sorry I edited the post. It's Issue Class Commented Aug 1, 2014 at 13:16

2 Answers 2

2

Change criteria.createAlias("Project", "Prj") to criteria.createAlias("project", "Prj"). The property for which you are trying to create an alias is project, so should go as the first argument of createAlias. Project is the class name.

Sign up to request clarification or add additional context in comments.

5 Comments

Still I'm not able to fetch data. But I'm not getting any error.
Can you set the 'show_sql' property of hibernate to true and run the generated sql on the database?
Thank you so much. :) But I'm not getting unique values. Getting duplicate entry for each issue in project :(
Does the sql give you duplicates?
yes, I was getting duplicate values from SQL. I used setResultTransformer to get unique values. Thanks
0

You have called the Hibernate property "ProjectId", not "Project".

criteria.createAlias("Project", "Prj");

This should be:

criteria.createAlias("ProjectId", "Prj");

1 Comment

Request processing failed; nested exception is org.hibernate.QueryException: could not resolve property: projectId of: com.dcm.search.bean.Issue

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.