title: Spring data CrudRepository findBy relationships
body: <p>I want to select all Foo entities that have any Bars that have status new. </p>
  
  <p>Here's what I tried:</p>
  
  <pre><code>@Entity
  @Table(name = "FOO")
  class Foo {
  
      @Id
      @Column(name = "ID")
      @GeneratedValue(strategy= GenerationType.IDENTITY)
      private Long id;
  
      @OneToMany
      private Set&lt;Bar&gt; bars;
  
     //...
  }
  
  
  
  public interface FooRepository extends CrudRepository&lt;Foo, Long&gt; {
  
  
      @Query("select m from Foo f where f.bars.status = 'NEW' ")
      public Page&lt;Foo&gt; findByBarStatus(Pageable pageable);
  
  }
  </code></pre>
  
  <p>But I get :</p>
  
  <pre><code>org.hibernate.exception.SQLGrammarException: could not prepare statement
  </code></pre>
  
  <p>I also tried writing join statement instead:</p>
  
  <pre><code>select f from Foo f inner join f.bars b where b.status = 'NEW'
  </code></pre>