-->
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: Composite Key Collection Problems
PostPosted: Tue Jul 11, 2006 1:52 pm 
Newbie

Joined: Tue Jul 11, 2006 12:09 pm
Posts: 7
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.0
I have two Tables:
<Table name=Question>
<key name=JOB>
<key name=QUESTIONNum>
<property name=SCLNAME>
</Table>

<Table name=Answers>
<key name=JOB>
<key name=SCLNAME>
<key name=SCLPUNCH>
</Table>

There is a one-to-many relationship between Question and Answers.
The problem is the table Answers does not have a property that QuestionNum can match up with. I wish to exclude QuestionNum from the Many-To-One mapping but if I do I get the error:

Foreign key (FK4012A9ADF4A27A66:st.tlkpscale [JOB])) must have same number of columns as the referenced primary key (st.tblquestion [JOB,QUENUMBER])

I have two classes mapped accordingly:
Mapping documents:
Code:
<class name="Question" table="st.question">
   <composite-id name="questionId" class="QuestionId">
      <key-property name="job" type="integer" column="JOB" />
      <key-property name="questionNumber" type="string" column="QUENUMBER" />
   </composite-id>

   <property name="sclName" type="string" length="15" column="SCLNAME" />

        <set name="answers" table="st.answers" inverse ="true" lazy="false" cascade="delete">
           <key>
              <column name="JOB" />
           </key>
          <one-to-many class="Answers"/>
       </set>

</class>

Code:
<class name="Answers"  table="st.answers" >
   
   <composite-id name="id" class="AnswersId">
      <key-property name="job" column="JOB"/>
      <key-property name="sclName" column="SCLNAME"/>
      <key-property name="sclPunch" column="SCLPUNCH"/>
   </composite-id>

</class>


Ideally I'd like to be able to select the Answers based upon the JOB and SCLNAME. If I add <column name="SCLNAME" /> to the <key> Hibernate puts the quenumber from the table into the sclname query which will return an empty set. Any help is appreciated.


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.