Hibernate Bi- Directional many to many mapping advice!
Posted
by Rob
on Stack Overflow
See other posts from Stack Overflow
or by Rob
Published on 2010-04-29T16:55:56Z
Indexed on
2010/04/29
16:57 UTC
Read the original article
Hit count: 321
hi all, i woundered if anyone might be able to help me out. I am trying to work out what to google for (or any other ideas!!) basically i have a bidirectional many to many mapping between a user entity and a club entity (via a join table called userClubs) I now want to include a column in userClubs that represents the role so that when i call user.getClubs() I can also work out what level access they have. Is there a clever way to do this using hibernate or do i need to rethink the database structure? Thank you for any help (or just for reading this far!!)
the user.hbm.xml looks a bit like
<set name="clubs" table="userClubs" cascade="save-update">
<key column="user_ID"/>
<many-to-many column="activity_ID"
class="com.ActivityGB.client.domain.Activity"/>
</set>
the activity.hbm.xml part
<set name="members" inverse="true" table="userClubs" cascade="save-update">
<key column="activity_ID"/>
<many-to-many column="user_ID"
class="com.ActivityGB.client.domain.User"/>
</set>
The current userClubs table contains the fields id | user_ID | activity_ID
I would like to include in there id | user_ID | activity_ID | role
and be able to access the role on both sides...
© Stack Overflow or respective owner