The Version
Code:
Hibernate 2.1.1
The MappingCode:
<hibernate-mapping>
<class name="Sample" table="sample">
<id name="id">
<generator class="native"/>
</id>
<property name="designation" unique="true" not-null="true" />
<set name="samplePoints" table="sample_point_status" lazy="true">
<key column="sample_id" />
<one-to-many class="SamplePointStatus"/>
</set>
</class>
<class name="SamplePointStatus" table="sample_point_status">
<composite-id name="id" class="SamplePointStatusId">
<key-property name="sampleId" column="sample_id"/>
<key-property name="stratumNumber" column="stratum_number"/>
<key-property name="samplePoint" column="sample_point_id" />
</composite-id>
<property name="sequenceNumber" column="sequence_number" not-null="true" />
<many-to-one name="samplePoint" column="sample_point_id" not-null="true" />
</class>
<class name="SamplePoint" table="sample_point">
<id name="id">
<generator class="native"/>
</id>
<property name="recorderId" column="recorder_id" unique="true" not-null="true" />
</class>
</hibernate-mapping>
The error :Code:
net.sf.hibernate.MappingException: Repeated column in mapping for class SamplePointStatus should be mapped with insert="false" update="false": sample_point_id
The Question:
This is a set theory problem :
I have a Sample with a population of SamplePoints. Each SamplePoint belongs to a subset within the Sample. This subset is represented by a SamplePointStatus (an id and attributes associated with the subset).
A SamplePoint can belong to one or more Samples, but within that Sample, it can only belong to one subset.
So, the mapping I built needed a composite key to make sure that the sample, sample point, and subset id were unique. I also needed setup a many-to-one for the SamplePoint based on the SamplePoint id which is part of the composite-id.
Hibernate exported the mapping fine and created the tables the right way, but when ever I try to get a SessionFactory, Configuration blows up and tells me that there are repeated columns.
I've read through a couple of posts about this but haven't seen a definate answer. I tried putting in the inser/update = false but Hibernate says that those two attributes are not part of that element.
Any ideas?