-->
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: Inserting new object and children using one-to-many mapping
PostPosted: Wed Aug 05, 2009 3:52 pm 
Newbie

Joined: Wed Aug 05, 2009 3:46 pm
Posts: 2
Hi,

I'm new to nHibernate and have been struggling trying to get an insert of a new object Question with child ISet of object QuestionAnswer.

I have the mapping correct and am setting the child set correct I believe passing in the Question object, however when it flushes I get a SQL error below!

could not insert: [Models.QuestionAnswer][SQL: INSERT INTO QuestionAnswer (AnswerText, IsCorrectAnswer, QuestionID) VALUES (?, ?, ?); select SCOPE_IDENTITY()]

Do i need to save the Question object first so the child objects know the value of its FK QuestionID? I would assume that nhibernate could and should insert the question and then use the relevant new ID in the inserting of the child objects.

Any ideas or help would be greatly appreciated.

Thanks,

Kev


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.