-->
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.  [ 2 posts ] 
Author Message
 Post subject: Problem With Shared Composite Key Property And Many-To-One
PostPosted: Tue Mar 23, 2004 5:35 pm 
Newbie

Joined: Sun Jan 18, 2004 5:03 pm
Posts: 12
Location: Texas
The Version
Code:
Hibernate 2.1.1


The Mapping
Code:
<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?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 23, 2004 6:02 pm 
Newbie

Joined: Sun Jan 18, 2004 5:03 pm
Posts: 12
Location: Texas
Okay, I found a way around this to stop the duplicate column message and to get a SessionFactory built, but part of me doesn't like the solution.

I just put a key-many-to-one into the composite-id and moved the SamplePoint object down into to the ID class. I had to modify the getter and setters in the SamplePointStatus to go through the ID class to get the SamplePoint.

Part of me is just not crazy about putting that object into the ID class.

Is this going to cause problems with the equals method I overrode?

Is this the correct use for a key-many-to-one?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.