Dealing with empty or null collection parameter in JPA
Inside org.springframework.data.jpa.repository.@Query annotation I check if field in a collection and possibly ignore collection if it is empty: @Query(""select e from #{#entityName} where e.type in :lst or 0 = :lstSize") List<Entity> findByLst(@Param("lst") List<XEnum> lst, @Param("lstSize") int lstSize); I call code as: List<XEnum> lst = ...; int lstSize = (lst == null) ? 0 : lst.size(); findByLst(lst, lstSize); For Oracle DB in case of lst = null Hibernate logged: DEBUG [nio-8443-exec-4] org.hibernate.SQL entity0_.type in (?) or 0=? TRACE [nio-8443-exec-4] org.hibernate.type.EnumType Bindin
0 upvotes
View original discussion ↗
Comments
Sign in or sign up to comment and upvote.
No comments yet.