【问题标题】:Getting MissingTokenException when I run the query through JPA通过 JPA 运行查询时出现 MissingTokenException
【发布时间】:2013-09-19 00:07:12
【问题描述】:

我正在使用 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 服务器中运行此查询,它会正常运行。 如果我遗漏了什么,请指出。

【问题讨论】:

    标签: java mysql jpa jpa-2.0 spring-data-jpa


    【解决方案1】:

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

    使用em.createNativeQuery()

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-04-21
      • 1970-01-01
      • 2019-11-11
      • 2018-02-20
      • 2014-05-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多