title: Spring Data - Spring Repository: selecting distinct values for a class attribute
body: <p>I have the following</p>
  
  <pre><code>@Entity
  public class Restaurant{
  
      @ManyToOne
      private City c;
      // more
  }
  
  @Entity
  public class City{
  
      private String name;
      // more
  }
  </code></pre>
  
  <p>I also have a repository </p>
  
  <pre><code>public interface RestaurantRepository extends JPARepository&lt;Restaurant, Long&gt; {
  // something to put here
  }
  </code></pre>
  
  <p>===EDIT====
  I have the list of ALL cities, but only some of them are associated to restaurants.</p>
  
  <p>I need to write a method in such respository to extract all cities that are referred by a Restaurant.</p>
  
  <p>In SQL I would just do the following:</p>
  
  <pre><code>SELECT CITY.id, CITY.name FROM CITY WHERE ID NOT IN (SELECT DISTINCT(city_id) FROM RESTAURANT)
  </code></pre>
  
  <p>Is there a way to obtain the same result using the name conventions as of <a href="http://docs.spring.io/spring-data/jpa/docs/1.4.3.RELEASE/reference/html/jpa.repositories.html" rel="nofollow">http://docs.spring.io/spring-data/jpa/docs/1.4.3.RELEASE/reference/html/jpa.repositories.html</a> ?</p>
  
  <p>Thanks.</p>