title: JPA select from collection with many-to-many association
body: <p>I have 2 Entity classes with Many-to-Many association.</p>
  
  <p>ModPm:</p>
  
  <pre><code>@Entity
  @Table(name = "MOD_PM")
  public class ModPm extends WebPageObject implements Serializable, IDBNamedEntity {
  
      private static final long serialVersionUID = 1L;
  
      public final static String Q_GET_WITHOUT_STATUS_FOR_SCOPE = "ModPm.getWithoutStatusForScope";
  
      @Id
      private long id;
      ....
      @ManyToMany
      @JoinTable(name = "MOD_PM_SCOPE_TYPES",
              joinColumns = @JoinColumn(name = "PM_ID"),
              inverseJoinColumns = @JoinColumn(name = "SCOPE_TYPE_ID")
      )
      private List&lt;ModScopeType&gt; modScopeTypes;
  </code></pre>
  
  <p>ModScopeType:</p>
  
  <pre><code>@Entity
  @Table(name = "MOD_SCOPES")
  @Cacheable
  public class ModScopeType extends WebPageObject implements Serializable {
  
      private static final long serialVersionUID = 1L;
  
      public final static String Q_GET_ALL = "ModScopeType.getAll";
  
      @Id
      @Column(name = "ID")
      private long id;
      ....
      //bi-directional many-to-many association to ModPm
      @ManyToMany
      @JoinTable(name = "MOD_PM_SCOPE_TYPES",
              joinColumns = @JoinColumn(name = "SCOPE_TYPE_ID"),
              inverseJoinColumns = @JoinColumn(name = "PM_ID")
      )
      private List&lt;ModPm&gt; modPms;
  </code></pre>
  
  <p>Is it possible to select entities from MOD_PM table which have record in MOD_PM_SCOPE_TYPES table for SCOPE_TYPE_ID=1?</p>
  
  <p>Native SQL Query:</p>
  
  <pre><code>SELECT ID, NAME FROM MOD_PM WHERE ID IN (SELECT PM_ID FROM MOD_PM_SCOPE_TYPES WHERE SCOPE_TYPE_ID=1)
  </code></pre>
  
  <p>How can I translate this query to JPQL?</p>