繁体   English   中英

Spring JPA HQL 枚举“in 子句”查询

[英]Spring JPA HQL enum “in clause” query

如何使用枚举列表编写 HQL“in 子句查询”?

预留。 这里的实体:

@Enumerated(EnumType.STRING)
private ReservationState state;

存储库在这里:

 @Query(value = "select rez from Reservation rez where (:state is null or rez.state in (:state))",countQuery="")
List<Reservation> getByState(@Param("state") List<ReservationState> state)

在这里请求:

localhost:8080/reservation/getbystate?state=ACCEPTED&state=CREATED

这里的错误:

antlr.NoViableAltException:意外的 AST 节点:{vector}

org.hibernate.hql.internal.ast.QuerySyntaxException:意外的 AST 节点:{vector}

如果我从查询中删除 null 检查,则此查询不适用于 null“状态”请求。 但是我通过了 state 无论如何这将起作用。 我需要同时传递 null 和 'n'length 的 List 参数。 我怎样才能做到这一点?

以这种方式工作

(rez.state in (:state) or :state is null)

代替

(:state is null or rez.state in (:state))

请试试这个

  @Query(value = "select rez from Reservation rez where (rez.state is null or rez.state in (:state))",countQuery="")
List<Reservation> getByState(@Param("state") List<ReservationState> state)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM