Eli*_*eva 5 java hibernate jpa spring-data-jpa spring-boot
UPD
@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);
Run Code Online (Sandbox Code Playgroud)
我有一个像上面这样的查询,我检查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_))]
Run Code Online (Sandbox Code Playgroud)
我已经找到了这个解决方案How to Skip @Param in @Query if is null or empty in Spring Data JPA
它描述了我的情况,但对我不起作用。我在用着spring-boot 1.5.9.RELEASE
如果向量为空,则可以产生 null,如果不为空,则产生第一个值
where (coalesce(:docTypes, null) is null or d.documentTypeName in :docTypes)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
689 次 |
| 最近记录: |