[英]Hibernate Criteria: nested exception is org.hibernate.QueryException: could not resolve property:
I'm trying get all data from isssue table that matches with projectname and Issue Id. 我正在尝试从isssue表中获取与projectname和Issue ID匹配的所有数据。 I'm getting following error.
我遇到以下错误。 please help me.
请帮我。
Tables Project ProjectID ProjectName 表项目 ProjectID ProjectName
Issue issueID identifier sourceStatus title severity description 发行 issueID标识符sourceStatus标题严重性描述
Project.java 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 问题.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 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
Change criteria.createAlias("Project", "Prj")
to criteria.createAlias("project", "Prj")
. 将
criteria.createAlias("Project", "Prj")
更改为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 ,因此应作为
createAlias
的第一个参数。 Project is the class name. 项目是类名。
You have called the Hibernate property "ProjectId", not "Project". 您已将休眠属性称为“ ProjectId”,而不是“ Project”。
criteria.createAlias("Project", "Prj");
This should be: 应该是:
criteria.createAlias("ProjectId", "Prj");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.