我在hibernate中有一个表,如下所示
价格 以下字段和值
--------------------------------------------------------------------------
| price_id | price | effective_date (mm/dd/yyyy) |inactive | product_id
--------------------------------------------------------------------------
| 1 | 10 | 01/01/2015 | N | 4
| 2 | 11 | 02/01/2015 | N | 4
| 3 | 12 | 08/29/2015 | N | 4
| 6 | 10 | 09/02/2015 | Y | 4
| 7 | 9 | 09/05/2015 | N | 4
--------------------------------------------------------------------------
price_id是一些独特的ID。 价格是产品的成本 effective_date - 当达到该日期的系统日期时应用于产品的价格。 有效 - 确定价格是否有效或不适用于产品。 product_id - 价格适用的产品
我在上表中有一个hibernate实体。使用hibenate @filter注释,如下所示
@FilterDef(name = "currentPrice")
@Filter(name = "currentPrice", condition = "price_id =(SELECT DISTINCT (CASE
WHEN (SELECT MAX (pp.price_id)
FROM price pp
WHERE pp.product_id = product_id
AND pp.effective_date <= SYSDATE
AND (pp.inactive != 'Y' OR pp.inactive IS NULL)) IS NULL
THEN (SELECT MAX (pp.price_id)
FROM price pp
WHERE pp.product_id = product_id
AND pp.effective_date IN (
SELECT MIN (pp.effective_date)
FROM price pp
WHERE pp.product_id = product_id
AND (pp.inactive != 'Y' OR pp.inactive IS NULL )))
ELSE (SELECT MAX (pp.price_id)
FROM price pp
WHERE pp.product_id = product_id
AND pp.effective_date <= SYSDATE
AND (pp.inactive != 'Y' OR pp.inactive IS NULL))
END)
FROM price prodPrice where prodPrice.product_id = product_id)"
public List<PriceData> getPrices() {
return this.prices;
}
i am trying to fetch the active price for the that is matching the system date in the filter.
问题:当我使用hibernate 3.2.6.ga版本时。
现在当我升级到hibernate 3.6.10或4.2.20时,我遇到了问题。 由hibernate构成的查询将别名附加到MAX聚合函数。 由于记录了SQLGrammer异常。
2015-08-29 17:52:15,092 WARN(http-8082-1)[SqlExceptionHelper(logExceptions:144)] SQL错误:904,SQLState:42000 2015-08-29 17:52:15,093 ERROR(http-8082-1)[SqlExceptionHelper(logExceptions:146)] ORA-00904:&#34; PRODUCTPRI0 _&#34;。&#34; MAX&#34;:无效的标识符
有没有解决方法来解决这个问题。为什么更高版本的hibernate会导致@Filter中的语句出现问题