title: How to find distinct rows with field in list using JPA and Spring?
body: <p>I am using Spring to connect to the db. I have an interface extending <code>CrudRepository&lt;People, Long&gt;</code> Here is the query I want execute on the db: <code>SELECT DISTINCT name FROM people WHERE name NOT IN UserInputSet</code>. I would prefer to do it without any sql annotation, so if it is possible without the <code>NOT</code> that's fine.</p>
  
  <p>Is there a way to do it? I looked at the spring doc, but I cannot find anything (<a href="http://docs.spring.io/spring-data/jpa/docs/current/reference/html/#repositories.query-methods.query-creation" rel="noreferrer">http://docs.spring.io/spring-data/jpa/docs/current/reference/html/#repositories.query-methods.query-creation</a>)</p>
  
  <hr>
  
  <p>This is what I tired but it is not working.</p>
  
  <pre><code>@Query("SELECT DISTINCT name FROM people WHERE name NOT IN (?1)")
  List&lt;String&gt; findNonReferencedNames(List&lt;String&gt; names);
  </code></pre>
  
  <p>this is the exception I get:</p>
  
  <pre><code>Error creating bean with name 'peopleRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Validation failed for query for method public abstract java.util.List de.test.tasks.persistence.PeopleRepository.findNonReferencedNames(java.util.List)!
  </code></pre>
  
  <p>and </p>
  
  <pre><code>Caused by: java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: people is not mapped [SELECT name FROM people WHERE name NOT IN (?1)]
  </code></pre>