如何修复HQL查询中的“意外令牌”错误

时间:2019-01-27 02:51:45

标签: java hibernate

我正在尝试执行以下SQL语句:

select reimb_id, first_name, last_name, amount, type_id, description, 
             submitted, status_id, resolved
    from ers.reimbursement
    left join ers.users on author=user_id
    order by status_id
    limit 20;

在HQL中。这是我的尝试:

String hql = "Select reimb_id, firstname, lastname, amount, type_id, " +
"description, submit_date, status_id, resolve_date " +
"from Reimb " +
"join Reimb.Users as data " +
"order by data.status_id desc";

Query q = session.createQuery(hql).setMaxResults(20);

但是,当我按下此HQL语句时,会出现以下异常:

  

org.hibernate.QueryException:无法解析路径[data.status_id],   意外令牌[数据] [选择reimb_id,名字,姓氏,金额,   type_id,说明,submit_date,status_id,resolve_date来自   com.ers.pojos.Reimb以data.status_id的数据顺序加入Reimb.Users   desc]

如果删除数据表达式,则会出现以下异常:

  

java.lang.IllegalStateException:节点没有数据类型:   org.hibernate.hql.internal.ast.tree.IdentNode +-[IDENT] IdentNode:   'firstname'{originalText = firstname}

我一直在使用它来尝试将其修复为无济于事:https://docs.jboss.org/hibernate/orm/3.3/reference/en-US/html/queryhql.html

以下是我相关的Java类和变量(至少是相关的类)

我的Reimb Java类:

@Entity
@Table(name = "reimbursement", schema = "ers")
public class Reimb {
    @Id
    @Column(name = "reimb_id")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private int reimb_id;

    @Column(name = "amount")
    private double amount;

    @Column(name = "submitted")
    private Timestamp submit_date;

    @Column(name = "resolved")
    private Timestamp resolve_date;

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

    @Column(name = "status_id")
    private int status_id;

    @Column(name = "type_id")
    private int type_id;

“我的用户” java类:

@Entity
@Table(name="users", schema = "ers")
public class Users {

    @Column(name = "FIRST_NAME")
    private String firstname;

    @Column(name = "LAST_NAME")
    private String lastname;

0 个答案:

没有答案