title: Hibernate Many to Many on many to
body: <p>I´m trying to map an existing database to Hibernate using annotations.
  The problem is as follows.</p>
  
  <p>'organization' and 'organization_roles' has a many to many relationship which is resolved in a 
  table 'organization_has_roles' using the two primary keys as a composite primary key in the join table. </p>
  
  <p>Next there is a 'users' table. Users can have a single role in multiple organizations. This is again resolved in a join table named 'users_has_organizations_and_role' which has a composite primary key of the 'user_id', 'organization_id' and 'organization_role_id' and a unique_index on the 'user_id' and 'organization_id'. </p>
  
  <p>The 'users_has_organizations_and_role' references the 'organization_has_roles' composite primary key(organization_id, organization_role_id) and the users table (user_id)</p>
  
  <p>I have not been able to find examples on this matter that worked.</p>
  
  <p>Is it possible to map this. Which Annotations should I use and how?</p>
  
  <p>I´m using Hibernate 4, although it might not matter.. </p>