我有我的库之一以下功能:
@RestResource(path = "filter", rel = "filter")
@Query("SELECT t "
+ "FROM Trip t "
+ "WHERE "
+ "(:from IS NULL OR t.startTs >= :from) "
+ "AND (:categories IS NULL OR t.category IN :categories) ")
Page<Trip> filter(
@Param("from") Instant from,
@Param("categories") List<Category> categories,
Pageable pageable);
所述Category
是被存储为一个枚举:
@Enumerated(EnumType.STRING)
在Trips
表。
当我做我的HTTP请求恰好与一个类别我得到正确的结果。这样做没有类别键值的请求时相同的行为。
htt*://localhost/filter?categories=PRIVATE
==>确定
htt*://localhost/filter
==>确定
当使用多个类别:
htt*://localhost/filter?categories=PRIVATE,BUSINESS
我发现了以下情况除外:
org.hibernate.hql.internal.ast.QuerySyntaxException:意想不到AST节点:FROM foo.bar.services.trips.model.Trip吨{矢量} [SELECT COUNT(t)其中(:从IS NULL OR t.startTs> = :从)AND(:categories_0_,:categories_1_为空或t.category IN(:categories_0_,:categories_1_))]
任何人有一个想法,我做错了什么吗?
请尝试以下之一:
1)请附上包括括号中的列表中的语句:
@Query("SELECT t "
+ "FROM Trip t "
+ "WHERE "
+ "(:from IS NULL OR t.startTs >= :from) "
+ "AND ((:categories IS NULL) OR (t.category IN :categories)) ")
括号类别浏览:2)括起来
t.category IN (:categories)