简体   繁体   English

休眠条件:嵌套异常是org.hibernate.QueryException:无法解析属性:

[英]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.

相关问题 休眠(非JPA)条件-org.hibernate.QueryException:无法解析属性: - Hibernate (not JPA) Criteria - org.hibernate.QueryException: could not resolve property: 休眠条件-org.hibernate.QueryException:无法解析属性: - Hibernate Criteria - org.hibernate.QueryException: could not resolve property: 休眠条件-org.hibernate.QueryException:无法解析属性: - Hibernate Criteria - org.hibernate.QueryException: could not resolve property: 获取Hibernate异常:org.hibernate.QueryException:无法解析属性 - Getting Hibernate Exception : org.hibernate.QueryException: could not resolve property org.hibernate.QueryException-无法解析属性 - org.hibernate.QueryException— could not resolve property org.hibernate.QueryException:无法解析属性 - org.hibernate.QueryException: could not resolve property HTTP状态500-请求处理失败; 嵌套的异常是org.hibernate.QueryException:无法解析属性 - HTTP Status 500 - Request processing failed; nested exception is org.hibernate.QueryException: could not resolve property 嵌入式标准属性上的休眠条件引发org.hibernate.QueryException:无法解析属性 - Hibernate Criteria on EmbeddedId property throws org.hibernate.QueryException: could not resolve property Hibernate-org.hibernate.QueryException:无法解析属性: - Hibernate - org.hibernate.QueryException: could not resolve property: 休眠限制+投影org.hibernate.QueryException:无法解析属性 - Hibernate restriction + projection org.hibernate.QueryException: could not resolve property
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM