我有以下查询,在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个参数。
请不要投下来的问题没有任何理由。 –