首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >跳过@Query中的@Param as列表,如果在Spring Data JPA : antlr.NoViableAltException: unexpected节点中为null

跳过@Query中的@Param as列表,如果在Spring Data JPA : antlr.NoViableAltException: unexpected节点中为null
EN

Stack Overflow用户
提问于 2018-01-26 17:35:14
回答 1查看 429关注 0票数 5

更新

代码语言:javascript
复制
    @Query(value = "select distinct d.documentId " +
        "from TrainingDocument d " +
        "where (:docTypes is null or d.documentTypeName in :docTypes)")
List<String> findDocByDocTypes(
        @Param("docTypes") List<String> docTypes);

我有一个类似上面的查询,我检查List<String> docTypes是否为null。如果使用docTypes == null,或者列表中只有一个元素,它就可以工作。一旦我有一个以上的元素,我就会得到:

代码语言:javascript
复制
org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected AST node: {vector} 
[select distinct d.documentId from com.example.model.TrainingDocument d 
where (:docTypes_0_, :docTypes_1_ is null or d.documentTypeName in
(:docTypes_0_, :docTypes_1_))]; nested exception is
java.lang.IllegalArgumentException:
org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected AST node: {vector} 
[select distinct d.documentId from com.example.model.TrainingDocument d
where (:docTypes_0_, :docTypes_1_ is null or d.documentTypeName in
(:docTypes_0_, :docTypes_1_))]

我已经找到了这个解决方案,How to skip @Param in @Query if is null or empty in Spring Data JPA它描述了我的情况,但对我不起作用。我正在使用spring-boot 1.5.9.RELEASE

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48458719

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档