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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:36:48+00:00 2026-05-24T13:36:48+00:00

When moving an object from one collection to another and when cascade is set

  • 0

When moving an object from one collection to another and when cascade is set to all-delete-orphan, I get the following exception:

deleted object would be re-saved by cascade (remove deleted object from associations)

I thought that nhibernate would not delete an object when it is referenced in another collection when you use all-delete-orphan.

Can anyone confirm that, when you have objects like Folders which contain Folders or Files and you move a File from one Folder to another, you should not get this exception?

I made a sample project in vs2010 which demonstrates this behavior. Can anyone say if my mappings are correct or if there is a bug in nhibernate?

FileMapping.cs

public class FileMapping: ClassMap<File>
{
    public FileMapping()
    {
        Id(x => x.Id, "Id").GeneratedBy.Native("File_seq");
        Map(x => x.Name, "Name").Not.Nullable();
        References(x => x.Folder).Not.Nullable().Column("idFolder");
    }
}

FolderMapping.cs

public class FolderMapping: ClassMap<Folder>
{
    public FolderMapping()
    {
        Id(x => x.Id, "Id").GeneratedBy.Native("Folder_seq");
        Map(x => x.Name, "Name").Not.Nullable();
        HasMany(x => x.Folders).Inverse().Cascade.AllDeleteOrphan().KeyColumn("idParentFolder");
        HasMany(x => x.Files).Inverse().Cascade.AllDeleteOrphan().KeyColumn("idFolder");
        References(x => x.ParentFolder).Nullable().Column("idParentFolder");
    }
}

Sample project: http://www.mediafire.com/?orxcw63aziq54xo
Instructions:

  1. make sure connectionstring in Project’s Properties is correct
  2. run project
  3. click 1st button: connect to database
  4. click top right button to create tables and sample data (2 folder objects and 1 file)
  5. click button to move file object to other folder object
  6. click button to persist chances: you will get the DeletedObjectException
  • 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-24T13:36:50+00:00Added an answer on May 24, 2026 at 1:36 pm

    NHibernate has a very local view on orphans. If an object is moved from folder A to folder B folder A considers it an orphan and therefore deletes it. Folder B wants to update the object and a conflict occurs.

    It is called re-parenting and you read about it here http://fabiomaulo.blogspot.com/2009/09/nhibernate-tree-re-parenting.html

    Basically this is a option to redefine what Orphan means in your collection so your objects don’t get deleted.

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

Sidebar

Related Questions

I'm new to C#. I'm moving from a non-object-oriented website to an object-oriented one.
So I'm looking at moving from MVC 1.0 to MVC 2.0 RTM . One
Ok so I'm trying to move items from one listbox to another by using
When moving a file from old.package to new.package I want two things to happen:
I am interested in moving a number of my projects from Visual Studio and
My team is moving from Visual SourceSafe to Subversion soon, while developing/supporting a legacy
We're looking at moving from a check-out/edit/check-in style of version control system to Subversion,
Is it possible to copy a function (or any object for that matter) from
From what I have read on the web, one of the most efficient algorithms
I have one object of b2Body class. But I was it to move just

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.