Hibernate version: Hibernate2 HEAD 2005-02-08
Hi,
I am trying to map from a parent table to a child table with composite Ids. I am not using a unique key because the tables are intended to be updated manually. It is easier to add new pages by adding the feature number and the page number than it is to remember a generated unique key.
The relationship is Feature -> Page -> Section. This is my mapping document:
<hibernate-mapping package="model">
<class name="Feature" table="feature" mutable="false">
<id name="featureNumber" unsaved-value="0" column="feature_number">
<generator class="assigned"/>
</id>
<property name="name"/>
<property name="description"/>
<list name="pages" lazy="true">
<key>
<column name="feature_number"/>
<column name="page_number"/>
</key>
<index column="page_number"/>
<one-to-many class="Page"/>
</list>
</class>
<class name="Page" table="page" mutable="false">
<composite-id>
<key-many-to-one name="feature" class="Feature"/>
<key-property name="pageNumber" column="page_number"/>
</composite-id>
<property name="title"/>
<property name="description"/>
<list name="sections" lazy="true">
<key>
<column name="feature_number"/>
<column name="page_number"/>
<column name="section_number"/>
</key>
<index column="section_number"/>
<one-to-many class="Section"/>
</list>
</class>
<class name="Section" table="section" mutable="false">
<composite-id>
<key-many-to-one name="page" class="Page">
<column name="feature_number"/>
<column name="page_number"/>
</key-many-to-one>
<key-property name="sectionNumber" column="section_number"/>
</composite-id>
<property name="title"/>
<property name="description"/>
<property name="image"/>
<property name="position"/>
</class>
</hibernate-mapping>
And this is the message
net.sf.hibernate.MappingException: Foreign key (section [feature_number,page_number,section_number])) must have same number of columns as the referenced primary key (page [feature,page_number])
at net.sf.hibernate.mapping.ForeignKey.setReferencedTable(ForeignKey.java:67)
...
Any suggestions on how to map this kind of relationship?
Thanks,
John.
|