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.