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);
I have a query like above, where I check List<String> docTypes
whether it is null
or not. With docTypes == null
or with only one element in the list it works. As soon as I have more than one element I get:
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_))]
I already found this solution How to skip @Param in @Query if is null or empty in Spring Data JPA
It describes my case but doesn't work for me.
I'm using spring-boot 1.5.9.RELEASE
You can yield null if your vector is empty, or yield the first value if is not
where (coalesce(:docTypes, null) is null or d.documentTypeName in :docTypes)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With