Hi,
I am a NHibernate newbiy but I have experiences with Hibernate.
I have the following problem. Just one relation between a person and an email address:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="Skillworks.Common.Examples.NHibernate.Person, Skillworks.Common.Examples"
table="PERSON">
<id name="Id" column="ID" unsaved-value="0">
<generator class="identity" />
</id>
<property name="Name" column="NAME" not-null="true" unique="false" />
<!--<bag name="Emails" inverse="true" lazy="false" order-by="ADDRESS" cascade="all">
<key column="PERSON_ID" />
<one-to-many class="Skillworks.Common.Examples.NHibernate.Email, Skillworks.Common.Examples" />
</bag>-->
<!--<bag name="Emails" inverse="true" cascade="all" table="EMAIL">
<key column="PERSON_ID"/>
<one-to-many class="Skillworks.Common.Examples.NHibernate.Email, Skillworks.Common.Examples"/>
</bag>-->
<set name="Emails" cascade="all" lazy="true">
<key column="PERSON_ID"/>
<one-to-many class="Skillworks.Common.Examples.NHibernate.Email, Skillworks.Common.Examples"/>
</set>
</class>
</hibernate-mapping>
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="Skillworks.Common.Examples.NHibernate.Email, Skillworks.Common.Examples" table="EMAIL">
<id name="Id" column="ID" unsaved-value="0">
<generator class="identity" />
</id>
<property name="Address" column="ADDRESS" not-null="true" unique="false" />
<many-to-one name="Person" column="PERSON_ID" class="Skillworks.Common.Examples.NHibernate.Person, Skillworks.Common.Examples" cascade="all" />
</class>
</hibernate-mapping>
The problem is that when I try to save a person with an email I got an SQL error, that the column PERSON_ID can't be null. If I define the colum as "nullable" hibernate is making an entry into the person table and one in the email table but it won't set the foreign key. Now I don't know what I am doing wrong?!
Thanks for every hint.