NHibernate free exception for moving objects between collections

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

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

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

Can someone confirm that when you have objects such as folders containing 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 that demonstrates this behavior. Can anyone tell if my mappings are correct or is there an error 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");
    }
}

: http://www.mediafire.com/?orxcw63aziq54xo :

  • , connectionstring .
  • 1- :
  • (2 1 )
  • , : DeletedObjectException
+3
1
+2

All Articles