我有一个sql查询,应该转换为HQL。我试图转换它,但我收到此错误:
org.hibernate.hql.internal.ast.QuerySyntaxException:意外令牌
如何将此sql查询重写为HQL查询?
select ProductsBase.PRODUCT_ID,
ProductsBase.PRODUCT_NAME,
ProductsBase.LIST_PRICE,
CategoryTranslations.CATEGORY_NAME,
CategoryTranslations.CATEGORY_ID
from products_base ProductsBase,
CATEGORY_TRANSLATIONS CategoryTranslations,
PRODUCT_TRANSLATIONS ProductTranslations
where CategoryTranslations.CATEGORY_ID(+) = ProductsBase.CATEGORY_ID
and ProductTranslations.PRODUCT_ID(+) = ProductsBase.PRODUCT_ID
and CategoryTranslations.LANGUAGE = 'EN'
and ProductTranslations.LANGUAGE = 'EN'
and ProductsBase.product_id in
(select PRODUCT_ID
from (SELECT OrderItems.product_id,
max(OrderItems.quantity) as Items_Ordered
FROM order_items OrderItems, products_base ProductsBase
WHERE ProductsBase.product_id = OrderItems.product_id
GROUP By OrderItems.product_id,
ProductsBase.Product_Name,
ProductsBase.category_id
ORDER BY Items_Ordered DESC))
我尝试过这个HQL,但是我收到了错误:
QuerySyntaxException:意外令牌
from ProductsBase pr , ProductTranslations prt ,CategoryTranslations ct where ct.productCategoriesBase.categoryId = pr.categoryId and pr.productId = prt.productsBase.productId and ct.language ='EN' and prt.language = 'EN' and pr.productId in
( select subquery.prId from ( select oi.productsBase.productId prId , max(oi.quantity) qoi from OrderItems oi , ProductsBase prin where oi.productsBase.productId = prin.productId group by oi.productsBase.productId , prin.productName , prin.categoryId order by qoi DESC) as subquery )
我该怎么办?如何解决这个HQL的问题或我可以用上面的HQL查询替换?