title: Spring 'NOT IN' in method naming does not work as it expected
body: <h1>Question</h1>
  
  <p>Is it bug, or it just my fail? Can you explain me what is wrong?</p>
  
  <h1>Code</h1>
  
  <p>I have created simple <strong>JPARepository</strong></p>
  
  <pre><code>@Repository
  interface UserRepository extends JpaRepository&lt;User, Long&gt; {
      User findByName(String name);
  
  
      Collection&lt;User&gt; findByIdNotIn(Collection&lt;Long&gt; users);
  }
  </code></pre>
  
  <p>It looks correct. And it works correct if <code>users</code> is not empty. But otherwise it works incorrect:</p>
  
  <pre><code>result = userRepository.findByIdNotIn([]);
  </code></pre>
  
  <p>It returns empty result, but it should be equals to result of <code>findAll</code> method call.</p>
  
  <pre><code>userRepository.findByIdNotIn([]).equals(userRepository.findAll());
  </code></pre>
  
  <h1>Also</h1>
  
  <p>To check result I have added <code>@Query</code> annotation to method</p>
  
  <pre><code>@Repository
  interface UserRepository extends JpaRepository&lt;User, Long&gt; {
      User findByName(String name);
  
      @Query('SELECT u FROM User u WHERE u.id NOT IN ?1')
      Collection&lt;User&gt; findByIdNotIn(Collection&lt;Long&gt; users);
  }
  </code></pre>
  
  <p>And in this case expected result was correct.
  Also I have tried write query using native Hibernate <code>CriteriaBuilder</code></p>
  
  <pre><code>CriteriaBuilder builder = entityManager.getCriteriaBuilder();
  CriteriaQuery&lt;User&gt; query = builder.createQuery(User.class);
  Root&lt;User&gt; root = query.from(User.class);
  
  query.where(builder.not(root.get("id").in([])));
  result = entityManager.createQuery(query.select(root)).getResultList();
  </code></pre>
  
  <p>And in this case expected result was correct too.</p>
  
  <h1>Additional Info</h1>
  
  <p>Result Hibernate queries:
  Correct result (using <code>@Query</code> annotation):</p>
  
  <pre><code>Hibernate: select user0_.id as id1_7_, user0_.name as name2_7_ from User user0_ where user0_.id not in  ()
  </code></pre>
  
  <p>Incorrect result(using method naming):</p>
  
  <pre><code>Hibernate: select user0_.id as id1_7_, user0_.name as name2_7_ from User user0_ where user0_.id not in  (?)
  </code></pre>
  
  <h1>My conclusion</h1>
  
  <p><strong>It looks like a Spring JPA bug</strong></p>
  
  <h1>New Additional Info</h1>
  
  <p>I spent a day in debuging <code>spring-data-jpa</code> source code, and I found that the problems occurs in <code>org.springframework.data.jpa.provider.PersistenceProvider</code> in method <code>potentiallyConvertEmptyCollection</code> for <strong><em>HIBERNATE</em></strong></p>
  
  <pre><code>@Override
          public &lt;T&gt; Collection&lt;T&gt; potentiallyConvertEmptyCollection(Collection&lt;T&gt; collection) {
              return collection == null || collection.isEmpty() ? null : collection;
          }
  </code></pre>
  
  <p>When collection is empty this function return <code>null</code> value. 
  But I have found, if this value replaced (<em>at runtime</em>) on empty collection again then the final result would be correct!!!</p>
  
  <h2>HAVE YOU ANY IDEA ABOUT THIS?!</h2>