Hi,
I'm having some trouble doing a many-to-many mapping on the following table-layout. As I see it the collection table is 'missing' an attribute. The application and role table are both using composite-id's.
Hibernate version:
2.1.6
Mapping documents:
<hibernate-mapping>
<class
name="Application"
table="APPLICATION"
dynamic-update="false"
dynamic-insert="false"
>
<composite-id
name="id"
class="ApplicationPK"
>
<key-property
name="companyId"
type="java.lang.Long"
column="COMPANYID"
/>
<key-property
name="applicationId"
type="java.lang.Long"
column="APPLICATIONID"
/>
</composite-id>
<bag name="roles" table="APPLROLE">
<key>
<column name="COMPANYID"/>
<column name="APPLICATIONID"/>
</key>
<many-to-many class="Role">
<column name="COMPANYID"/>
<column name="ROLEID"/>
</many-to-many>
</bag>
</class>
</hibernate-mapping>
<hibernate-mapping>
<class
name="Role"
table="ROLE"
dynamic-update="false"
dynamic-insert="false"
>
<composite-id
name="id"
class="RolePK"
>
<key-property
name="companyId"
type="java.lang.Long"
column="COMPANYID"
/>
<key-property
name="roleId"
type="java.lang.String"
column="ROLEID"
/>
</composite-id>
</class>
</hibernate-mapping>
Name and version of the database you are using:
MySql 4.0.21
Here is the table layout.
CREATE TABLE APPLICATION (
COMPANYID bigint(20) NOT NULL default '0',
APPLICATIONID bigint(20) NOT NULL default '0',
PRIMARY KEY (COMPANYID,APPLICATIONID)
);
CREATE TABLE APPLROLE (
COMPANYID bigint(20) NOT NULL default '0',
APPLICATIONID bigint(20) NOT NULL default '0',
ROLEID varchar(50) NOT NULL default ''
);
CREATE TABLE ROLE (
COMPANYID bigint(20) NOT NULL default '0',
ROLEID varchar(50) NOT NULL default '',
PRIMARY KEY (COMPANYID,ROLEID)
);
With this table layout and this mapping I get the following exception: net.sf.hibernate.MappingException: Repeated column in mapping for collection: com.nordija.bizicalc.persistent.Application.roles column: COMPANYID.
The challenge is that I can't change the layout of the APPLROLE to contain two COMPANYID's so that COMPANYID isn't repeated.
So how do I construct this many-to-many?
Morten
|