spring数据JPA CriteriaBuilder.isNull返回语法错误



规格:

public Predicate toPredicate(Root<Hotel> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
Predicate predicate = root.get("starRating").in(s);
if (unrated) {
predicate = cb.or(predicate, cb.isNull(root.get("starRating")));
}
return predicate;
}

其中,sSet

SQL日志:Hibernate: select hotel0_.hotel_id as hotel_id1_16_, hotel0_.star_rating as star_ra13_16_ where hotel0_.active=? and (hotel0_.star_rating in () or hotel0_.star_rating is null) order by lower(hotel0_.hotel_name) asc

错误:ERROR 6828 --- [nio-8080-exec-1] o.h.engine.jdbc.spi.SqlExceptionHelper : ERROR: syntax error at or near ")"

异常:org.springframework.dao.InvalidDataAccessResourceUsageException: could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet

我在这里错过了什么?

查询中的问题在这里:hotel0_.star_rating in ()。在此点之前对集合s进行空检查:

if(s != null && !s.isEmpty()){
predicate = root.get("starRating").in(s);
}

最新更新