title: Spring Data JPA - how to fetch parents by child id?
body: <p>I have Parent and Child entities with @ManyToMany annotation:</p>
  
  <pre><code>@Entity
  @Table(name = "parent")
  public class Parent {
  
      @Id
      @GenericGenerator(name = "uuid-gen", strategy = "uuid2")
      @GeneratedValue(generator = "uuid-gen",strategy=GenerationType.IDENTITY)
      private String id;
  
      @ManyToMany(fetch = FetchType.LAZY)
      @JoinTable(name = "parents_childs",
          joinColumns = {@JoinColumn(name = "parent_id", nullable = false, updatable = false)},
          inverseJoinColumns = {@JoinColumn(name = "child_id", nullable = false, updatable = false)})
      private List&lt;Child&gt; childs;
  }
  </code></pre>
  
  <p>And Child entity:</p>
  
  <pre><code>@Entity
  @Table(name="child")
  public class Child {
  
      @Id
      @GenericGenerator(name = "uuid-gen", strategy = "uuid2")
      @GeneratedValue(generator = "uuid-gen",strategy=GenerationType.IDENTITY)
      private String id;
  
  }
  </code></pre>
  
  <p>My task is to find all Parents that contains Child with a specific id. I tried to do this in my repository this way:</p>
  
  <pre><code>@Query("select p from Parent p where p.childs.id = :childId and --some other conditions--")
  @RestResource(path = "findByChildId")
  Page&lt;Visit&gt; findByChild(@Param("childId") final String childId, final Pageable pageable);
  </code></pre>
  
  <p>Exception:</p>
  
  <pre><code>java.lang.IllegalArgumentException: org.hibernate.QueryException: illegal attempt to dereference collection [parent0_.id.childs] with element property reference [id] [select p from Parent p where p.childs.id = :childId and --some other conditions--]
  </code></pre>
  
  <p>I know that it's possible to solve adding <code>_</code> to method name like <code>findByChilds_Id</code> (as <a href="https://stackoverflow.com/a/33438696/2114952">here</a>) but I can't find how to write this in <code>@Query</code> annotation. </p>
  
  <p>How to write it using JPQL?</p>