NHibernate, one to zero or one relationship problem

I have two classes. One is called Employee, and the other EmployeeDetails, which has zero or one relationship with its parent class 'Employee'. In other words, there are times when we need to store additional data in this class 'EmployeeDetails', but this is not necessarily the norm. The db structure is pretty simple, because EmployeeDetails uses the same identifier as its parent.

The problem I ran into is deleting the class 'EmployeeDetails'from the class 'Employee', I would suggest that setting the object to null will lead to trick and flush sessions, but the record in the database will not be deleted.

My mappings ...

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
    <class name="StudioBusinessLayer.Data.Structure.Employee, StudioBusinessLayer" table="tblEmployee" lazy="false">
        <id name="ID" column="ID" type="int">
            <generator class="native" />
        </id>

        <property name="Name" column="Name" not-null="true" type="string" length="100" />
        <!-- etc -->

        <one-to-one constrained="false" name="EmployeeDetails" class="StudioBusinessLayer.Data.Structure.EmployeeDetails, StudioBusinessLayer" cascade="all-delete-orphan"  />

    </class>
</hibernate-mapping>

... and for the EmployeeDetails class ...

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
    <class name="StudioBusinessLayer.Data.Structure.EmployeeDetails, StudioBusinessLayer" table="tblDetails" lazy="false">
        <id name="ID" column="DetailsID" type="int">
            <generator class="foreign">
                <param name="property">Employee</param>
            </generator>
        </id>

        <property name="Address" column="Address" not-null="false" type="string" length="1000" />
        <property name="ContactEmail" column="ContactEmail" not-null="false" type="string" length="255" />
        <property name="ContactName" column="ContactName" not-null="false" type="string" length="255" />
        <property name="ContactTelephone" column="ContactTelephone" not-null="false" type="string" length="255" />
        <property name="ZipCode" column="ZipCode" not-null="true" type="string" length="100" />

        <many-to-one name="Employee" class="StudioBusinessLayer.Data.Structure.Employee, StudioBusinessLayer" column="DetailsID" insert="false" update="false"></many-to-one>

    </class>
</hibernate-mapping>

, , .

...

+5
2

, all-delete-orphan "--" NHibernate. . . , , EmployeeDetails , all-delete-orphan .

+2

EmployeeDetails . , "--" Employee " ", , tblDetails Employee.Id. NHibernate, , tblDetails , Employee.

UPDATE:

, "--", . , , , , .

0

All Articles