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
|