Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

composite key, saving in two tables is giving NPE.

 
vani venkat
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

i try my best to explain scenario of my tables.

there could be many records in attachment table for a given candidateSeq and positionSeq. this is represented as one to many with many id being set as foriegn key like in following two tables.

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 between candidatePositionAttachment and Attachment?

CandidatePositionAttachment.hbm.xml


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.



really appreciate any help or pointer regarding this.


Note: this worked fine when i had one to one mapping between these two tables. and attachmentSeq was not included in primary key.




and created rows in attachment as well as candidatePositionAttachment tables were inserted really well. however, now the requirement is to add attachmentSeq as one of the keys of composite key.
Can some one guide me how to do that?
 
vani venkat
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
as of now, i am going with work around,
1. save a record in child table(attachment here) and then get the id of record
2. set it as primary key of candidate, position, attachment. save this bean.


i wish there is a better way to handle it in hibernate way of doing using objects rather than dealing with child records first. but with composite keys it is not allowing me to map attachment as object. and childs id won't be available before attachment is inserted, it fails while saving candidate position attachment. i donot know a way to actually save attachment first and then insert candidate position attachment in one call to session.save()






 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic