gpt4 book ai didi

java - 当我通过 JPA 运行查询时出现 MissingTokenException

转载 作者:行者123 更新时间:2023-11-30 01:18:38 25 4
gpt4 key购买 nike

我正在使用 JPA 运行以下查询并得到下面提到的异常:

JPA 代码:

int count = em.createQuery(QueryCollections.getSoldProductUpdateQuery(billGuid).toString()).executeUpdate();

这是查询:

Query:  
UPDATE at_product currentproduct
JOIN
(SELECT
atbillfields.billeditemguid AS productguid,
COUNT(*) AS number_of_people_bought,
SUM(atbillfields.billeditemqty) AS soldquantity
FROM
jtbillingtest.at_salesbill atsalesbill
JOIN jtbillingtest.at_billfields atbillfields ON atsalesbill.billbatchguid = atbillfields.billbatchguid
WHERE
atsalesbill.billguid = '41'
GROUP BY atbillfields.billeditemguid) soldproductdetails ON soldproductdetails.productguid = currentproduct.productguid
SET
currentproduct.productQuantity = currentproduct.productQuantity - soldproductdetails.soldquantity

jpa 抛出异常。

> Exception , line 1, column 34: syntax error at [JOIN]. Internal
> Exception: MissingTokenException(inserted [@-1,0:0='<missing
> SET>',<62>,1:34] at JOIN) at
> org.eclipse.persistence.internal.jpa.EntityManagerImpl.createQuery(EntityManagerImpl.java:1477)
> at myjavfxapp.dal.ProductDal.updateSoldProducts(ProductDal.java:46)
> at
> myjavfxapp.controller.BillingController$6.handle(BillingController.java:421)
> at

但是如果我直接在 MySQL 服务器中运行这个查询,它就会运行而不会失败。如果我遗漏了什么,请指出。

最佳答案

JPQL 和 SQL 不是同一种语言。您正在尝试使用 executeQuery() 执行 SQL 查询,该查询需要 JPQL 查询。

使用em.createNativeQuery()

关于java - 当我通过 JPA 运行查询时出现 MissingTokenException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18800946/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com