我需要从相对表中获取全部数据,所以我正在使用这种方式(我会在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列获取所有数据?
该方法createQuery需要一个HQL查询字符串。
createQuery
HQL是一种面向对象的查询语言。
HQL解释SELECT R.*为选择*对象的成员字段R。
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')