title: Hibernate and PostgreSQL - checking if a collection passed in setParameterList is empty
body: <p>I'm building a query where I want to pass a collection as a parameter:</p>
  
  <pre><code>List&lt;String&gt; items = new LinkedList();
  //adding optional items
  Query query = s.getNamedQuery("myQueryName").setParameterList("item", items);
  </code></pre>
  
  <p>My query looks like this:</p>
  
  <pre><code>SELECT i from Item i
  //... not important things
  WHERE ( i.name in (:item) )
  </code></pre>
  
  <p>but I want to make it optional, so the items list could be empty. But when it's empty, I get an exception:</p>
  
  <pre><code>org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected end of subtree
  </code></pre>
  
  <p>So I tried to use some functions like:</p>
  
  <pre><code>SELECT i from Item i
  //... not important things
  WHERE ( (:item) is null or i.name in (:item) )
  
  SELECT i from Item i
  //... not important things
  WHERE ( (:item) is empty or i.name in (:item) )
  
  SELECT i from Item i
  //... not important things
  WHERE ( size(:item)=0 or i.name in (:item) )
  </code></pre>
  
  <p>but none of it seems to work. How can I solve this problem and checking if an item name is in a list only if the list is not empty?</p>