-->
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.  [ 4 posts ] 
Author Message
 Post subject: Mapping Exception
PostPosted: Thu Feb 16, 2006 9:29 am 
Newbie

Joined: Wed Feb 08, 2006 6:17 am
Posts: 9
Hi All,
I'm sure this error msg is self-explanatory, but how do I fix it?

Thanks

Angus

org.hibernate.MappingException: Foreign key (FKE5A0BD21AC0BCC8B:Participation [id])) must have same number of columns as the referenced primary key (Participation [roleid,id])

Here's my mapping:

<class name="com.rose.ahr.hibernate.Role" table="Role">

<id name="id" type="int" column="id">

<generator class="native"/>

</id>

<set name="participations" table="Participation">

<key column="roleid"/>

<many-to-many column="id" class="com.rose.ahr.hibernate.Participation"/>

</set>

<property name="roledefnid" column="roledefnid"/>

<property name="classcode" column="classcode"/>

<property name="moodcode" column="moodcode"/>

<property name="code" column="code"/>

<property name="zrole" column="zrole"/>

<property name="playerentityid" column="playerentityid"/>

<property name="scoperentityid" column="scoperentityid"/>

<property name="effectivestarttime" column="effectivestarttime"/>

<property name="effectiveendtime" column="effectiveendtime"/>

<property name="msaccessid" column="msaccessid"/>

</class>



<class name="com.rose.ahr.hibernate.Participation" table="Participation" >

<id name="id" type="int" column="id">

<generator class="native"/>

</id>

<property name="moodcode" column="moodcode"/>

<property name="classcode" column="classcode"/>

<property name="typecode" column="typecode"/>

<property name="roleid" column="roleid"/>

<property name="actid" column="actid"/>

<property name="quantity" column="quantity"/>

<property name="zdescription" column="zdescription"/>

<property name="functioncode" column="functioncode"/>

<property name="participation" column="participation"/>

<property name="conceptid" column="conceptid"/>

<property name="msaccessid" column="msaccessid"/>

</class>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 16, 2006 10:01 am 
Expert
Expert

Joined: Tue Dec 07, 2004 6:57 am
Posts: 285
Location: Nürnberg, Germany
If you want to map a many to many relationship you have to provide a mapping column to the collection mapping, not the column of participation.

<set name="participations" table="ParticipationRoles">

<key column="roleid"/>

<many-to-many column="id" class="com.rose.ahr.hibernate.Participation"/>

</set>

Is this really a many-to-many association or is it a one-to-many association?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 16, 2006 10:11 am 
Newbie

Joined: Wed Feb 08, 2006 6:17 am
Posts: 9
I guess I need it to be a one-to-many mapping then as I may not be permitted to add tables How would I do this? Would I still be able to use the SET approach?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 16, 2006 10:27 am 
Expert
Expert

Joined: Tue Dec 07, 2004 6:57 am
Posts: 285
Location: Nürnberg, Germany
That ist fairly straight forward...

<set name="participations">
<key column="roleid"/>
<one-to-many class="com.rose.ahr.hibernate.Participation"/>
</set>

In this case you have to consider if you want to navigate from Participation to role. Then you have to map a many-to-one relationship into Participation and mark the set participations in Role as inverse="true"

I strongly recommend you to read chapters 6 and 7 from the reference documentation since collection / association mappings aren't trivial


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

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.