一尘不染

期望IDENT的Hibernate HQL问题发现为“ *”。

sql

我需要从相对表中获取全部数据,所以我正在使用这种方式(我会在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其中P.id =
R.project_id和O.id = R.offer_order_id并且O.type =’ORDER’和(P.status
=’PENDING’或P.status =’PROTECTED’)]

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


阅读 137

收藏
2021-03-10

共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')
2021-03-10