title: Spring Data JPA findBy a collection
body: <p>Im working on a route planing system in Java, using JPA.
  I need to create a findBy method to find an route by a list of the cities its containing.
  Here are the classes:</p>
  
  <pre><code>@Entity
  public class Route {
  
      @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
      private List&lt;City&gt; cities = new ArrayList&lt;&gt;();
      .
      .
  }
  
  @Entity
  public class City {
      .
      .
  }
  </code></pre>
  
  <p>Now I tried, but wasn't surprised it didn't work, the following:</p>
  
  <pre><code>@Repository
  public interface RouteRepository extends JpaRepository&lt;Route, Long&gt; {
      Optional&lt;Route&gt; findByCities(List&lt;City&gt; city);
  }
  </code></pre>
  
  <p>Is there an easy way to do it with JPA, or do I have to write a difficult own @Query and somehow iterate, to find an entity by a collection?</p>