首页 > 解决方案 > HTTP 状态 500 - 意外令牌:,靠近第 1 行,第 129 列

问题描述

错误如下:

HTTP 状态 500 - 请求处理失败;嵌套异常是 org.hibernate.hql.internal.ast.QuerySyntaxException: 意外令牌:,靠近第 1 行,第 129 列 [从 invoicedetails i 中选择零件编号、零件描述、发票编号、数量,零件 p WHERE i.invoicenumber in :invoiceList,i。零件编号 = p.partNo AND 数量 < 0 ]

我尝试运行查询并将记录保存在 xlx 文件中。但是当我执行它时返回错误意外令牌。我是否以正确的方式编写查询?

查询在 SQL 工作台上运行良好

你们能帮我解决问题吗。非常感谢您的帮助。谢谢

实体类

public class SpecialOrder {

    public String partdescription;

    public Integer invoicenumber;

    public String partnumber;

    public Integer quantity;

    public Integer year;

    public SpecialOrder() {
        super();
    }

    public SpecialOrder(Integer invoicenumber, String partnumber, Integer quantity, Integer year,
            String partdescription) {
        super();
        this.invoicenumber = invoicenumber;
        this.partnumber = partnumber;
        this.quantity = quantity;
        this.year = year;
        this.partdescription = partdescription;
    }

    public String getPartdescription() {

        return partdescription;
    }

    public Integer getInvoicenumber() {

        return invoicenumber;
    }

    public String getPartnumber() {

        return partnumber;
    }

    public Integer getQuantity() {

        return quantity;
    }

    public Integer getYear() {

        return year;
    }

    public void setPartdescription(String partdescription) {

        this.partdescription = partdescription;
    }

    public void setInvoicenumber(Integer invoicenumber) {

        this.invoicenumber = invoicenumber;
    }

    public void setPartnumber(String partnumber) {

        this.partnumber = partnumber;
    }

    public void setQuantity(Integer quantity) {

        this.quantity = quantity;
    }

    public void setYear(Integer year) {

        this.year = year;
    }

控制器类

@RequestMapping("specialorder")
    public ModelAndView SpecialOrder(@RequestParam("invoiceno") String invoiceno, Model map, HttpSession session,
            ModelAndView mav) throws ConnectException {

        AppUser user = (AppUser) session.getAttribute("user");
        if (user == null) {
            throw new OrderNotFoundException();
        } else {

            List<Integer> invoiceNoList = new ArrayList();
            if (invoiceno.contains(",")) {
                String[] array = invoiceno.split(",");
                for (String s : array) {
                    invoiceNoList.add(Integer.parseInt(s));
                }
            } else {
                invoiceNoList.add(Integer.parseInt(invoiceno));
            }
            List<SpecialOrder> invoiceList = ordersService.getSpecialOrder(invoiceNoList);
            System.out.println("invoice list  = " + invoiceList);

            mav.clear();
            mav.setView(new SpecialOrderExcelView());
            // mav.setViewName("specialorderpage");
            mav.addObject("user", user);
            mav.addObject("branch", branch);
            mav.addObject("appcss", appcss);
            mav.addObject("sysdate", InsightUtils.getNewUSDate());
            mav.addObject("invoiceList", invoiceList);
        }
        return mav;

    }

服务等级

@Transactional
    public List<SpecialOrder> getSpecialOrder(List<Integer> invoiceList) throws ConnectException {

        List<SpecialOrder> getspecialorder = new ArrayList<>();

        Session session = sessionFactory.getCurrentSession();
        String hSql = "Select partnumber, partdescription, invoicenumber, quantity " + "from invoicedetails i, parts p "
                + "WHERE i.invoicenumber in :invoiceList, i.partnumber = p.partNo AND quantity < 0 ";

        Query query = session.createQuery(hSql);

        query.setParameterList("invoiceList", invoiceList);

        getspecialorder = query.list();

        session.flush();
        session.clear();

        return getspecialorder;
    }

标签: javaspringspring-mvc

解决方案


我检查了https://www.eversql.com/sql-syntax-check-validator/上的查询,它不喜欢逗号代替 AND (​​实际上在您收到的错误消息中的位置 129)和期望in后面跟括号中的内容(它也不喜欢冒号,但那是因为它是 SQL 而不是 HQL 所以不理解参数)。它确实接受以下内容(没有冒号,我在之后恢复了)。

Select
partnumber,
  partdescription,
  invoicenumber,
  quantity
from
  invoicedetails i,
  parts p
WHERE
  i.invoicenumber in (:invoiceList)
  AND i.partnumber = p.partNo
  AND quantity < 0

我相信这对你有用。


推荐阅读