小编典典

预期IDENT的Hibernate HQL问题发现“ *”

hibernate

我需要从相对表中获取全部数据,所以我正在使用这种方式(我会在sql中使用它)

    private static final String SELECT_OOPR_TO_SEND = "SELECT R.* " +
                                                      "FROM offerOrderProjectRel R, offerOrder O, project P " +
                                                      "WHERE P.id = R.project_id and O.id = R.offer_order_id " +
                                                      "and O.type = 'ORDER' and (P.status = 'PENDING' or P.status ='PROTECTED')" ;
;


    @SuppressWarnings("unchecked")
    public List<OfferOrderProjectRel> findAllOfferOrderToSendToSalesmans() {
        Query q = getSession().createQuery(SELECT_OOPR_TO_SEND);
        List<OfferOrderProjectRel> list = q.list();
        return list;
    }

启动此代码后,我得到了该错误:

org.hibernate.hql.internal.ast.QuerySyntaxException:期望IDENT, 在第1行第10列附近
找到“ * ” [SELECT R. FROM offerOrderProjectRel R,offerOrder O,项目P WHERE P.id
= R.project_id和O.id = R.offer_order_id并且O.type =’ORDER’和(P.status
=’PENDING’或P.status =’PROTECTED’)]

那么,如何使用hibernate从R列获取所有数据?


阅读 241

收藏
2020-06-20

共1个答案

小编典典

该方法createQuery需要一个HQL查询字符串。

HQL是一种面向对象的查询语言

HQL解释SELECT R.*为选择*对象的成员字段R

*不是的成员字段R。是吗?..

要选择所有使用的成员字段R

SELECT R
FROM offerOrderProjectRel R, offerOrder O, project P
WHERE P.id = R.project_id and O.id = R.offer_order_id
and O.type = 'ORDER' and (P.status = 'PENDING' or P.status ='PROTECTED')
2020-06-20