title: How to write a HQL query for Many To Many Associations?
body: <p>I have 3 tables, <code>Role[roleId, roleName]</code>, <code>Token[tokenID, tokenName]</code> &amp; <code>ROLETOKENASSOCIATION[roleId, tokenID]</code>. The 3rd one was created automatically by hibernate. Now if i simply write a Query to get all the objects from Role class means, it gives the all role objects along with the associated tokenID &amp; tokenName.</p>
  
  <p>I just wanted the association as unidirectional. i.e: Roles--->Tokens
  So the annotation in the Role class looks like, </p>
  
  <pre><code>@Id
  @GeneratedValue(strategy=GenerationType.AUTO)
  private int roleId;
  private String roleName;
  
  @ManyToMany
  @JoinTable(name="ROLE_TOKEN_ASSOCIATION",
   joinColumns={@JoinColumn(name="roleId")},
   inverseJoinColumns={@JoinColumn(name="tokenID")})
  private List&lt;Token&gt; tkns;
      //Getters &amp; Setters
  </code></pre>
  
  <p>Now i want the tokenNames for the specific roleId.
  First i made a query like this <code>SELECT tkns.tokenName FROM Role WHERE Role.roleId=:roleId</code>
  But, i ended up with some dereference error.</p>
  
  <p>Then i changed the query to <code>SELECT tkns FROM Role r WHERE r.roleId=:roleId</code>
  Now i have got what i wanted. But it comes with roleId too. </p>
  
  <p>How shall i get tokenName itself?
  Actually my problem is solved, but i would like to know how to do it.</p>
  
  <p><em>It ll be helpful to me, if anyone explains the Query Construction.</em></p>
  
  <p>Any suggestions!!</p>