title: Criteria Query Many To Many
body: <p>I have created the HQL of below mentioned SQL but I am unable to execute it by Criteria and Sub query. Please help me to execute the following queries (SQL &amp; HQL) through Criteria. Thanks in <strong>Advance</strong>...</p>
  
  <p><strong>SQL:</strong></p>
  
  <pre><code>SELECT * FROM app_interface ain WHERE ain.id IN (SELECT ai.id FROM app_interface ai INNER JOIN app_module_interface ami ON ami.interface_id = ai.id INNER JOIN app_module am ON am.id = ami.module_id WHERE am.id = :id
  </code></pre>
  
  <p><strong>HQL:</strong></p>
  
  <pre><code>FROM AppModule oam WHERE oam.id IN(SELECT am.id FROM AppModule am INNER JOIN am.appRoles ar WHERE ar.id = :id)
  </code></pre>
  
  <p>Through Criteria Needed…..?????</p>
  
  <p>Scenario:</p>
  
  <pre><code>public class AppModule implements java.io.Serializable {
  @Id
  @GeneratedValue(strategy = GenerationType.AUTO)
  @Column(name = "id", unique = true, nullable = false)
  private Integer id;
  
  @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "appModules")  
  private Set&lt;AppRole&gt; appRoles = new HashSet&lt;AppRole&gt;(0);
  </code></pre>
  
  <p>} </p>
  
  <p>public class AppRole implements java.io.Serializable {</p>
  
  <pre><code>@Id
  @GeneratedValue(strategy = GenerationType.AUTO)
  @Column(name = "id", unique = true, nullable = false)
  private Integer id;
  
  @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
  @OrderBy("name")
  @JoinTable(name = "app_role_module", joinColumns = {
  @JoinColumn(name = "role_id", nullable = false, updatable = false)}, inverseJoinColumns = {
      @JoinColumn(name = "module_id", nullable = false, updatable = false)})
  private Set&lt;AppModule&gt; appModules = new HashSet&lt;AppModule&gt;(0);
  </code></pre>
  
  <p>}</p>