Hi, i'm going to try explain my problem again.
I have an object for the class SubmitExercise with this mapping file:
<?xml version="1.0" encoding="utf-8" ?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.0"> <class name="Middleware.Exercises.SubmitExercise, Middleware" table="Elearn_SubmitExercises"> <id name="SubmitExerciseID" column="SubmitExerciseID" type="Int32" length="4" unsaved-value="0"> <generator class="identity"/> </id> <property name="Late" column="Late" type="Boolean" length="1"/> <property name="DateStart" column="DateStart" type="DateTime" length="8"/> <property name="DateFinish" column="DateFinish" type="DateTime" length="8"/> <property name="Score" column="Score" type="Single" length="9"/> <list name="SubmitQuestions" table="Elearn_SubmitQuestions" cascade="all"> <key column="SubmitExerciseID"/> <index column="Indice"/> <one-to-many class="Middleware.Exercises.SubmitQuestion, Middleware"/ </list>
</class> </hibernate-mapping>
That represents an exercise that have a list of submited questions by the students.
Tha mapping file for the submitQuestion is :
<?xml version="1.0" encoding="utf-8" ?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="Middleware.Exercises.SubmitQuestion, Middleware" table="ELearn_SubmitQuestions"> <id name="SubmitQuestionID" column="SubmitQuestionID" type="Int32" length="4" unsaved-value="0"> <generator class="identity"/> </id> <property name="Grade" column="Grade" type="Single" length="9"/> <property name="SubmitExerciseID" column="SubmitExerciseID" type="Int32" length="4"/> <property name="QuestionID" column="QuestionID" type="Int32" length="4"/> <one-to-one name="Answer" class="Middleware.Exercises.SubmitAnswer, Middleware" cascade="all"/> </class> </hibernate-mapping>
And finnaly i have a mapping file for the SubmitAnswer class that have 2 types a simple TextAnswer or a SubmitChoiceAnswer and have this mapping file:
<?xml version="1.0" encoding="utf-8" ?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="Middleware.Exercises.SubmitAnswer, Middleware" table="Elearn_SubmitAnswer"> <id name="SubmitAnswerID" column="SubmitAnswerID" type="Int32" length="4" unsaved-value="0"> <generator class="foreign"> <param name="property">SubmitQuestion</param> </generator> </id> <one-to-one name="SubmitQuestion" class="Middleware.Exercises.SubmitQuestion, Middleware" constrained="true"/> <joined-subclass name="Middleware.Exercises.SubmitTextAnswer, Middleware" table="Elearn_SubmitTextAnswer"> <key column="SubmitAnswerID"/> <property name="TextAnswer" column="Text" type="string"/> </joined-subclass> <joined-subclass name="Middleware.Exercises.SubmitChoiceAnswer, Middleware" table="Elearn_SubmitChoiceAnswer"> <key column="SubmitAnswerID"/> <list name="ChoiceAnswer" table="Elearn_SubmitChoiceAnswer2" cascade="all"> <key column="SubmitChoiceAnswerID"/> <index column="ChoiceOrder"/> <composite-element class="Middleware.Exercises.AnswerOption, Middleware"> <property name="Text" column="Text" type="string"/> <property name="Valid" column="Valid" type="boolean"/> </composite-element> </list> </joined-subclass> </class>
So when i try so save an object SubmitExercise i do that:
I read de object from de session and pass de ID:
SubmitExercise exameLido = (SubmitExercise)session.Load(typeof(SubmitExercise), ID);
then I set the property SubmitQuestions equal to the questions that the user post like this:
exameLido.SubmitQuestions=(IList)questoes; session.SaveOrUpdate(exameLido); transaction.Commit(); session.Close(); and i got the error that i describe in de first post.
If you want more information take a look at the post "Urgent - List Mapping problem"
Thanks for your help.
Hugo Alves
</hibernate-mapping> [/b]
|