title: Dealing with empty or null collection parameter in JPA
body: <p>Inside <code>org.springframework.data.jpa.repository.@Query</code> annotation I check if field in a collection and possibly ignore collection if it is empty:</p>
  
  <pre><code>@Query(""select e from #{#entityName} where e.type in :lst or 0 = :lstSize")
  List&lt;Entity&gt; findByLst(@Param("lst") List&lt;XEnum&gt; lst, @Param("lstSize") int lstSize);
  </code></pre>
  
  <p>I call code as:</p>
  
  <pre><code>List&lt;XEnum&gt; lst = ...;
  int lstSize = (lst == null) ? 0 : lst.size();
  findByLst(lst, lstSize);
  </code></pre>
  
  <p>For Oracle DB in case of <code>lst = null</code> Hibernate logged:</p>
  
  <pre><code>DEBUG [nio-8443-exec-4] org.hibernate.SQL
  entity0_.type in (?) or 0=?
  TRACE [nio-8443-exec-4] org.hibernate.type.EnumType
  Binding null to parameter: [1]
  TRACE [nio-8443-exec-4] org.hibernate.type.descriptor.sql.BasicBinder
  binding parameter [2] as [INTEGER] - [0]
  </code></pre>
  
  <p>For case of <code>lst = new LinkedList&lt;&gt;()</code> Hibernate logged:</p>
  
  <pre><code>DEBUG [nio-8443-exec-5] org.hibernate.SQL
  entity0_.type in ( ) or 0=?
  TRACE [nio-8443-exec-5] org.hibernate.type.descriptor.sql.BasicBinder
  binding parameter [1] as [INTEGER] - [0]
  ERROR [nio-8443-exec-5] org.hibernate.engine.jdbc.spi.SqlExceptionHelper
  ORA-00936: missing expression
  </code></pre>
  
  <p>and it is syntactically invalid in SQL*PLUS also: </p>
  
  <pre><code>select 1 from dual where 1 in ();
  </code></pre>
  
  <p>Can I omit <code>lstSize</code> and still check if collection is not provided - return all elements?</p>
  
  <p>How can I deal with empty list and Oracle <code>()</code> syntax error?</p>
  
  <p>Actually I have large JPQL expression that handle several cases of empty arguments with single call. My goal to keep simple method instead of writing several specialized methods, using <code>if/else</code> or Critetia builder...</p>
  
  <p>For example ignoring empty parameters can be archived with:</p>
  
  <pre><code> ... and (e.field = :fieldVal or :fieldVal is null)
  </code></pre>
  
  <p><strong>UPDATE</strong> Relevant resources:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/2488930/passing-empty-list-as-parameter-to-jpa-query-throws-error">Passing empty list as parameter to JPA query throws error</a></li>
  <li><a href="https://hibernate.atlassian.net/browse/HHH-8091" rel="noreferrer">https://hibernate.atlassian.net/browse/HHH-8091</a> (Hibernate produces SQL - "in ()" - which is invalid in at least Oracle, MySQL and Postgres)</li>
  </ul>