【发布时间】:2017-01-04 19:58:48
【问题描述】:
我正在尝试将IN 操作与@Query 注释与JPA 一起使用。我收到以下错误:-
antlr.NoViableAltException: unexpected AST node: {vector}
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:2112)
org.springframework.dao.InvalidDataAccessApiUsageException: org.hibernate.hql.internal.ast.QuerySyntaxException:
unexpected AST node: {vector}
[ [select o FROM Stock o where (:productlist_0_, :productlist_1_, :productlist_2_, :productlist_3_ is null or o.productsid IN (:productlist_0_, :productlist_1_, :productlist_2_, :productlist_3_) )
我的 Java 代码如下:-
@Query("SELECT o FROM Stock o where (:productlist is null or o.productsid IN (:productlist) ) ")
List<Stockdiary> getAllStock(Pageable pageable, @Param("productlist") List<Products> productlist)
当我在productlist 中只有单个项目时,这可以正常工作。但是当我在productlist 中有多个项目时,查询会出现如下错误:-
select o FROM Stock o where (:productlist_0_, :productlist_1_, :productlist_2_, :productlist_3_ is null or o.productsid IN (:productlist_0_, :productlist_1_, :productlist_2_, :productlist_3_
我看过这个link,但这个解决方法对我不起作用。
我尝试通过带和不带括号的:productlist。
【问题讨论】:
-
当参数是集合时,您的 JPA 提供程序似乎无法处理“:param IS NULL”,或者可能是它与“OR”的组合。因此,将其作为提供程序的错误提出。