Java Hibernate查询异常

时间:2017-04-24 13:59:40

标签: java hibernate hql

错误消息:org.hibernate.hql.ast.QuerySyntaxException:意外令牌

 @SuppressWarnings("unused")
    @Transactional
    public List<String> getPartsFromMainOrder(String orders) {
        Session session = sessionFactory.getCurrentSession();

        String sql = "SELECT distinct partno FROM VendorOrderedItems  WHERE orderno in (:OrderNo)"
                + " ORDER BY partno";
        Query query = session.createQuery(sql);
         query.setInteger("OrderNo", Integer.parseInt(orders));
        List<String> partsList = query.list();
        session.flush();
        session.clear();

        return partsList;
    }

第一种方法查询正在运行。当它到达query.setParameter(“Partno”,partno);

时发生意外令牌错误
 @SuppressWarnings("unused")
    @Transactional
    public List<SelectedOrderItems> getSelectedOrderItems(List<String> lqs, String orders) {
        Session session = sessionFactory.getCurrentSession();
        List<SelectedOrderItems> lso = new ArrayList<SelectedOrderItems>();
        MultiMap multiMap = new MultiValueMap();
        String[] ord = orders.split(",");
        for (String partno : lqs) {
            String str1 = "SELECT price , orderno, quantity FROM vendorordereditems WHERE partno =:partNo "
                    + " AND orderno in (" + orders + ") "

                    + " AND price > 0 " + "ORDER BY price,orderno desc Limit 1";
            Query query = session.createQuery(str1);

            query.setParameter("partNo", partno);

1 个答案:

答案 0 :(得分:0)

问题似乎在+“AND orderno in(”+ orders +“)”

为什么不一次删除它并尝试。如果有效,请将其替换为

AND orderno in(:orders)

你可以参考 passing list to IN clause in HQL or SQL?