I am trying to map a many-to-many relationship using a mapping object. The object names are:
Account
Group
AccountGroupAssignment
I need the mapping object because there are properties I need to store that are related to the account's assignment to the group.
I can create a getGroupAssociations() function on both the Account and Group objects just fine. What i want to do (and cant get working) is create convenience methods like getGroups() and getAccounts() on the Account and Group objects respectively.
When I add the following to the GroupBean.hbm.xml file, it alters the primary keys on the AccountGroupAssignment table, changing the PK from the id column to a composite key between (group_id, account_id):
Code:
<set name="members" table="account_group">
<key column="group_id"/>
<many-to-many class="AccountBean" column="account_id" />
</set>
This altering of PK seems to confuse Hibernate later when it is trying to edit/update the collection.
Below are my mapping files:
Code:
<hibernate-mapping package="net.cg.ioweu.model">
<class name="AccountBean" table="accounts">
<cache usage="read-write"/>
<id name="id" column="id" unsaved-value="null">
<generator class="native"/>
</id>
...
<set name="groupAssignments" table="account_group" inverse="true">
<key column="account_id"/>
<one-to-many class="AccountGroupAssignmentBean"/>
</set>
...
</class>
</hibernate-mapping>
<hibernate-mapping package="net.cg.ioweu.model">
<class name="AccountGroupAssignmentBean" table="account_group">
<id name="id" column="id" unsaved-value="null">
<generator class="native"/>
</id>
...
<many-to-one name="account" column="account_id" class="AccountBean"/>
<many-to-one name="group" column="group_id" class="GroupBean"/>
</class>
</hibernate-mapping>
<hibernate-mapping package="net.cg.ioweu.model">
<class name="GroupBean" table="groups">
<cache usage="read-write"/>
<id name="id" column="id" unsaved-value="null">
<generator class="native"/>
</id>
...
<set name="members" table="account_group">
<key column="group_id"/>
<many-to-many class="AccountBean" column="account_id" />
</set>
<set name="groupAssignments" table="account_group" cascade="save-update" >
<key column="group_id"/>
<one-to-many class="AccountGroupAssignmentBean"/>
</set>
...
</class>
</hibernate-mapping>
Any help you can provide would be greatly appreciated.
I am working on WinXP, MySQL 3.23.xx
Thank you.