更新
@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
或列表中只有一个元素时,它可以工作。一旦我有多个元素,我就会得到以下错误:
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
:docTypes_0_, :docTypes_1_ is null
是无效的)。使用JPA提供程序的日志来确定哪一个,并向相关人员报告错误。 - user8558216