title: HQL delete associations from many to many mapping
body: <p>I Have two entities CRImageType &amp; CRVariable with a many to many relation as follows:</p>
  
  <p><strong>CRImageType entity:</strong></p>
  
  <pre><code>@Entity
  @Table(name = "imageviewer_crimagetype")
  public class CRImageType implements Serializable   {
      private static final long serialVersionUID = 1L;
  
      @Id
      @GeneratedValue
      @Column(name = "ImTypeId")
      private Long imTypeId;
  
      @Column(name = "ImTypeName")
      private String imTypeName;
  
      @Column(name = "ImTypeDescription")
      private String imTypeDescription;
  
      @ManyToMany(cascade = {CascadeType.ALL})
      @JoinTable(name="imageviewer_imtype_variable", 
      joinColumns={@JoinColumn(name="ImTypeId")}, 
      inverseJoinColumns={@JoinColumn(name="VarId")})
      private Set&lt;CRVariable&gt; crvariables = new HashSet&lt;CRVariable&gt;();
  </code></pre>
  
  <p><strong>CRVariable entity:</strong></p>
  
  <pre><code>@Entity
  @Table(name = "imageviewer_crvariable")
  public class CRVariable implements Serializable   {
  
      private static final long serialVersionUID = 1L;
  
      @Id
      @GeneratedValue
      @Column(name = "VarId")
      private Long varId;
  
      @Column(name = "VarName")
      private String varName;
  
      @Column(name = "VarDescription")
      private String varDescription;
  
      @ManyToMany(mappedBy="crvariables")
      private Set&lt;CRImageType&gt; crimagetypes = new HashSet&lt;CRImageType&gt;();
  </code></pre>
  
  <p>In my database the relation is mapped by two tables "imageviewer_crimagetype" &amp; "imageviewer_crvariable" and a third one <strong>"imageviewer_imtype_variable"</strong> for their many to many relation.</p>
  
  <p>I would like only to DELETE association records from table <strong>"imageviewer_imtype_variable"</strong>. How can be done using an HQL query since i can not directly access "imageviewer_imtype_variable table.</p>
  
  <p>I would like the HQL equivalent of an SQL query like </p>
  
  <pre><code>delete from imageviewer_imtype_variable where ImTypeId='%%%'
  </code></pre>