-->
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: MappingException: must have same number of columns
PostPosted: Wed Apr 15, 2009 10:36 am 
Newbie

Joined: Wed Apr 15, 2009 6:34 am
Posts: 1
Hi,

I m quite new to Hibernate but I m currently failing to get this to work:

A Document can have many Annotations.
An Annotation has a Descriptor and many Qualifiers (the order matters).

I have set up my Annotation mapping correctly:
//snip
<class name="Annotation" table="p2d_association">
<id name="id" column="annotation_id">
<generator class="native"/>
</id>
<many-to-one name="descriptor" column="descriptor_id" />
<list name="qualifiers" table="p2d2q_association">
<key>
<column name="annotation_id"/>
</key>
<index column="position"/>
<many-to-many column="qualifier_id" class="Qualifier"/>
</list>
</class>
</hibernate-mapping>
//snip
<class name="Qualifier" table="qualifiers">
<id name="id" column="qualifier_id" />
<property name="name" column="name"/>
<property name="annotation" column="annotation"/>
</class>
//snip

<class name="Descriptor" table="descriptors">
<id name="id" column="descriptor_id" />
<property name="descriptor_class" column="descriptor_class"/>
<property name="heading" column="heading"/>
</class>
</hibernate-mapping>

I can access persistent annotations from my code and play with them however once I try to integrate them with the Document:

//snip
<class name="Document" table="documents" mutable="false">
<id name="id" column="document_id">
<generator class="native"/>
</id>


<set name="annotations" table="p2d_association">
<key column="document_id"/>
<many-to-many column="annotation_id" unique="true" class="Annotation"/>
</set>

When I run this I get the following exception:

Initial SessionFactory creation failed.org.hibernate.MappingException: Foreign key (FK20ADBDDA84DF936D:p2d2q_association [annotation_id])) must have same number of columns as the referenced primary key (p2d_association [document_id,annotation_id])

So is this because of the way Hibernate maps classes across tables here? p2d_association primary key is annotation_id and p2d2q_association has a composite key annotation_id and qualifier_id.

Is there an way to solve this problem and allow me to map these classes so I can do this easily? Have I missed something in the documentation?

Many thanks in advance

Nathan


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.