Hibernate version: NHibernate 1.2
Database Schema :
Course (ID, Code)
Student (ID, Name, CourseID)
PS: All the column is not null
Course Mapping:
Code:
<class name="school.Course, SchoolApp" table="Course" lazy="false">
<id name="ID" column="ID" type="Int32" unsaved-value="0">
<generator class="native"/>
</id>
<property name="Code" column="Code" type="int" length="10" not-null="true"/>
<set name="Students" lazy="true" cascade="save-update" inverse="false">
<key column="CourseID"/>
<one-to-many class="school.Student, SchoolApp"/>
</set>
</class>
Student Mapping:
Code:
<class name="school.Student, SchoolApp" table="Student" lazy="false">
<id name="ID" column="ID" type="Int32" unsaved-value="0">
<generator class="native"/>
</id>
<property name="Name" column="Name" type="string" length="30" not-null="true"/>
</class>
I enabled the show SQL properties, when I save the Student object, the CourseID will not inserted. Seem it is not null, so the error will occur.
In java hibernate, i can solve the problem by define the not-null property in the key.
<key column="CourseID" not-null="true"/>
But seems NHibernate not support the not-null in key. Did anyone know how to solve this problem?