我有以下查詢,在MySQL中完美工作。但是當我在HQL中轉換相同的查詢時,它顯示異常。HQL查詢異常QuerySyntaxException異常令牌:> =
在MySQL:
SET @periodDate='1988-07-01';
SET @completionDate='1957-06-30';
SELECT * FROM building_register_period WHERE active = 1
AND start_period_date <= @periodDate
AND (CASE WHEN end_period_date IS NOT NULL THEN end_period_date >= @periodDate ELSE TRUE END)
AND (CASE WHEN constructed_start_date IS NOT NULL THEN constructed_start_date <= @completionDate ELSE TRUE END)
AND (CASE WHEN constructed_end_date IS NOT NULL THEN constructed_end_date >= @completionDate ELSE TRUE END);
在休眠
StringBuilder hql = new StringBuilder(" from BuildingRegisterPeriodModel brpm where brpm.active=true ");
if(propertyValue1!=null && !propertyValue1.equals("") && propertyValue2!=null && !propertyValue2.equals("")) {
hql.append("and brpm.startPeriodDate <= :periodDate and (case when brpm.endPeriodDate is not null then brpm.endPeriodDate >= :periodDate else true end) and (case when brpm.constructedStartDate is not null then brpm.constructedStartDate <= :constructedDate else true end) and (case brpm.constructedEndDate is not null then brpm.constructedEndDate >= :constructedDate else true end) ");
}
這裏,periodDate和constructedDate是2個參數。
請不要投下來的問題沒有任何理由。 –