【发布时间】:2014-08-21 00:50:27
【问题描述】:
我有以下 HQL 查询。当我运行它时,我得到了异常:
org.hibernate.hql.ast.QuerySyntaxException:意外令牌:开启
我的代码如下。有人知道如何解决这个问题吗?
def results = LineItem.executeQuery("\
select \
li_ch.eventId as event_id, \
sum(CASE li_ch.lineItemType WHEN :product THEN 1 WHEN :refund THEN (CASE li_p.lineItemType WHEN :product THEN -1 ELSE 0 END) ELSE 0 END) as sold, \
sum(li_ch.amount) as gross \
from \
LineItem li_ch LEFT JOIN LineItem li_p on li_ch.parentLineItem.id = li_p.id, \
Sale s \
where \
s.id = li_ch.sale.id AND \
li_ch.eventId in (238141) AND \
s.saleStatusType in (:paid, :refunded, :partialRefunded) AND \
li_ch.lineItemType in (:product, :refund) \
group by li_ch.eventId", [product: LineItemType.PRODUCT, refund: LineItemType.REFUND, paid: SaleStatusType.PAID, refunded: SaleStatusType.REFUNDED, partialRefunded: SaleStatusType.PARTIAL_REFUND])
这给出了以下异常:
[2014-08-21 09:34:52,666] hql.PARSER line 1:371: unexpected token: on
[2014-08-21 09:34:52,685] errors.GrailsExceptionResolver QuerySyntaxException occurrwhen processing request: [GET] /inventory/events/salesData - parameters:
eventIds: 238141
unexpected token: on near line 1, column 371 [ select li_ch.eventId as event_id, sum(CASE li_ch.lineItemType WHEN :product THEN 1 WHEN :refund THEN (CASE li_p.lineItemType WHEN :product THEN -1 ELSE 0 END) ELSE 0 END) as sold, sum(li_ch.amount) as gross from com.acme.inventory.domain.LineItem li_ch LEFT JOIN LineItem li_p on li_ch.parentLineItem.id = li_p.id, com.acme.inventory.domain.Sale s where s.id = li_ch.sale.id AND li_ch.eventId in (238141) AND s.saleStatusType in (:paid, :refunded, :partialRefunded) AND li_ch.lineItemType in (:product, :refund) group by li_ch.eventId]. Stacktrace follows:
org.hibernate.hql.ast.QuerySyntaxException: unexpected token: on near line 1, column 371 [ select li_ch.eventId as event_id, sum(CASE li_ch.lineItemType WHEN :product THEN 1 WHEN :refund THEN (CASE li_p.lineItemType WHEN :product THEN -1 ELSE 0 END) ELSE 0 END) as sold, sum(li_ch.amount) as gross from com.acme.inventory.domain.LineItem li_ch LEFT JOIN LineItem li_p on li_ch.parentLineItem.id = li_p.id, com.acme.inventory.domain.Sale s where s.id = li_ch.sale.id AND li_ch.eventId in (238141) AND s.saleStatusType in (:paid, :refunded, :partialRefunded) AND li_ch.lineItemType in (:product, :refund) group by li_ch.eventId]
at com.acme.inventory.services.SaleRestService$$EOnaEzWy.eventSaleData(SaleRestService.groovy:15)
at com.acme.inventory.controllers.SaleRestController.eventSaleData(SaleRestController.groovy:13)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
at java.lang.Thread.run(Thread.java:695)
【问题讨论】:
-
意外的令牌
ON就像我说的那样,对吗?问题是关键字 ON
标签: hibernate grails hql grails-2.0