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 656051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T22:40:19+00:00 2026-05-13T22:40:19+00:00

The scenario is as follows, I have 3 objects (i simplified the names) named

  • 0

The scenario is as follows,

I have 3 objects (i simplified the names) named Parent, parent’s child & child’s child
parent’s child is a set in parent, and child’s child is a set in child.

mapping is as follows (relevant parts)

parent

<set name="parentset"
     table="pc-table"
     lazy="false"
     fetch="subselect"
     cascade="all-delete-orphan"
     inverse="true">
  <key column=FK_ID_PC" on-delete="cascade"/>
  <one-to-many class="parentchild,parentchild-ns"/>
</set>

parent’s child

<set name="childset"
     table="cc-table"
     lazy="false"
     fetch="subselect"
     cascade="all-delete-orphan"
     inverse="true">
  <key column="FK_ID_CC" on-delete="cascade"/>
  <one-to-many class="childschild,childschild-ns"/>
</set>

What i want to achieve is that when i delete the parent, there would be a cascade delete all the way trough to child’s child. But what currently happens is this.

(this is purely for mapping test purposes)
getting a parent entity (works fine)

IQuery query = session.CreateQuery("from Parent where ID =" + ID);
IParent doc = query.UniqueResult<Parent>();

now the delete part

session.Delete(doc);
transaction.Commit();

After having solved the ‘cannot insert null value’ error with cascading and inverse i hopes this would now delete everything with this code, but only the parent is being deleted.

Did i miss something in my mapping which is likely to be missed? Any hint in the right direction is more than welcome!


Diego, thank you for the to the point answer. (and explanation)

I went with removing the on-delete="cascade", this because I like as much control as possible in code and not in the database.

The code posted below is the (working) result.

parent

<set name="parentset"     
     table="pc-table"     
     cascade="all-delete-orphan"     
     inverse="true"
     batch-size="5">     
  <key column=FK_ID_PC"/>     
  <one-to-many class="parentchild,parentchild-ns"/>     
</set>

parent’s child

<set name="childset"            
     table="cc-table"     
     cascade="all-delete-orphan" 
     batch-size="5"  
     inverse="true">            
  <key column="FK_ID_CC">            
  <one-to-many class="childschild,childschild-ns"/>            
</set>

Hope this helps people with the same problem!

  • 1 1 Answer
  • 3 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-13T22:40:19+00:00Added an answer on May 13, 2026 at 10:40 pm

    By setting on-delete="cascade" on the keys, you are letting the DB handle the cascading.

    Are you generating your schema with NHibernate?

    I just reproduced your example and it worked fine with and without that attribute. When removing it, NHibernate does the cascading.

    BTW, using lazy="false" fetch="subselect" is not something that you should do by default. If you remove those attributes, leave on-delete="cascade" and change cascade to save-update, you’ll only have two queries to retrieve and delete a Parent.

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

Sidebar

Related Questions

My scenario is as follows: I have some objects (Messages) that can be tagged
The architecture for this scenario is as follows: I have a table of items
The scenario I am using LINQ is as follows: I have a method that
My scenario is as follows. I have 7 tabs (one for each day) using
I have query regarding the disposing of an object. The scenario is as follows.
Hi I'm having a problem updating child objects in the following scenario. The mappings
I am new to jsp and servlet. My scenario is as follows I have
My scenario is as follows: I have a client-server application. The client is deployed
Let me cut to the chase. My scenario is as follows: I have custom
My scenario is as follows: I have an addin call which queries the server

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.