Java 通过JPA运行查询时获取MissingTokenException
我正在使用JPA运行以下查询,并得到以下提到的异常: JPA代码:Java 通过JPA运行查询时获取MissingTokenException,java,mysql,jpa,jpa-2.0,spring-data-jpa,Java,Mysql,Jpa,Jpa 2.0,Spring Data Jpa,我正在使用JPA运行以下查询,并得到以下提到的异常: JPA代码: int count = em.createQuery(QueryCollections.getSoldProductUpdateQuery(billGuid).toString()).executeUpdate(); 以下是查询: Query: UPDATE at_product currentproduct JOIN (SELECT atbillfiel
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
>异常,第1行,第34列:[JOIN]处的语法错误。内部的
>异常:MissingTokenException(在联接处插入[@-1,0:0='SET>',1:34])位于
>org.eclipse.persistence.internal.jpa.EntityManagerImpl.createQuery(EntityManagerImpl.java:1477)
>在myjavfxapp.dal.ProductDal.updateSoldProducts(ProductDal.java:46)上
>在
>myjavfxapp.controller.BillingController$6.handle(BillingController.java:421)
>在
但是,如果我直接在MySQL服务器上运行这个查询,它就会正常运行。
如果我遗漏了什么,请指出。JPQL和SQL不是同一种语言。您正在尝试使用
executeQuery()
执行SQL查询,这需要一个JPQL查询
使用em.createNativeQuery()