hi,
i have two tables with one to many relation. first table has composite key as primary key.
CandidatePositionAttachment table
PRIMARY KEY (candidateSeq, positionSeq, attachmentSeq)
FOREIGN KEY (attachmentSeq) REFERENCES CSS_Attachment
CSS_Attachment table
PRIMARY KEY attachmentSeq.
now how do I create mapping of one to many between candidatePositionAttachment and Attachment?
CandidatePositionAttachment.hbm.xml
Code:
<hibernate-mapping package="com.callidus.ssln.server.bean">
<class name="CandidatePositionAttachment" table="CSS_CandidatePositionAttachment" lazy="false">
<composite-id name="candidatePositionPK" class="com.callidus.ssln.server.bean.CandidatePositionPK">
<key-property name="candidateSeq" column="candidateSeq" />
<key-property name="positionSeq" column="positionSeq" />
[b]<key-many-to-one[/b] name="attachmentSeq" column="attachmentSeq" class="Attachment"/>
</composite-id>
<property name="status"/>
<property name="createDate"/>
<!-- <many-to-one name="video" class="Attachment" column="attachmentSeq" not-null="true" cascade="all" lazy="false" unique="true"/> -->
</class>
</hibernate-mapping>
is this correct? however it is not many to one mapping we have between these tables but it is one to many. and there is no key-one-to-many for this.
Requirement is to save multiple attachments for a given candidateId and positionId. using the above mapping, following code to save attachment for a given candidateId and positionId is giving null pointer exception when session.save is called. please point out what mistake i am doing.
Attachment videoAttachment = new Attachment();
CandidatePositionPK candidateJobPK = new CandidatePositionPK();
candidateJobPK.setCandidateSeq(1L);
candidateJobPK.setPositionSeq(1L);
candidateJobPK.setAttachmentSeq(videoAttachment);
CandidatePositionAttachment candidateJobVideo = new CandidatePositionAttachment();
candidateJobVideo.setId(candidateJobPK);
candidateJobVideo.setStatus("RECEIVED");
session.save(candidateJobVideo);