Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4602748
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T00:02:10+00:00 2026-05-22T00:02:10+00:00

I have two classes. One is called Employee and the other EmployeeDetails that has

  • 0

I have two classes. One is called Employee and the other EmployeeDetails that has a zero or one relationship with its parent 'Employee' class. In other words, there are occasions where we need to store additional data into this 'EmployeeDetails' class but this isn’t necessarily the norm. The db structure is pretty simple with the ‘EmployeeDetails’ sharing the same ID as its parent.

The problem I’ve got is deleting the 'EmployeeDetails' class from the 'Employee' class, I would have imagined that setting the object to null would have done the trick and flushing sessions but the record in the DB is not removed.

My mappings are…

<?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>

Insertions and updates work fine, but I’ve been struggling to find the switch that makes this work for deletions.

Any help or suggestions are gratefully received…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T00:02:11+00:00Added an answer on May 22, 2026 at 12:02 am

    Unfortunately all-delete-orphan is not supported for one-to-one relation in NHibernate yet. See this issue or this SO question for more details. It seems that there is no other way than deleting EmployeeDetails by your own or use an event listener that will emulate all-delete-orphan for one-to-one.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two classes, one that inherits from the other. The base class is
I have the following two classes, one inherits from the other Class A{ void
So I have two classes. One is a class called Main. The Main class
I have two classes. One class has a variable Image plane = null; in
I have two classes one called Person the other called Student I have been
I have two classes one the Driver and the other one called FilterOut. In
I have two classes, one called Grocery and the other one called Strings In
I have two classes called Lecturer and Course. My Lecturer class has a List
I have two classes in Grails application , Employee has hasMany(one To Many relations)
I have two classes one of which inherits from the other. Im trying to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.