-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: many-to-many mapping challenge using composite-id
PostPosted: Thu Sep 23, 2004 3:47 am 
Newbie

Joined: Thu Sep 23, 2004 3:26 am
Posts: 1
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.