database - NHibernate : delete error -


model: have model in 1 installation can contain multiple "computer systems".

database: table installations has 2 columns name , description. table computersystems has 3 columsn name, description , installationid.

mappings:

i have following mapping installation:

<?xml version="1.0" encoding="utf-8"?>  <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="myprogram.core" namespace="myprogram">    <class name="installation" table="installations" lazy="true">      <id name="id" column="id" type="int">       <generator class="native" />     </id>      <property name="name" column="name" type="string" not-null="true" />     <property name="description" column="description" type="string" />       <bag name="computersystems" inverse="true" lazy="true" cascade="all-delete-orphan">       <key column="installationid" />       <one-to-many class="computersystem" />     </bag>    </class>  </hibernate-mapping> 

i have following mapping computersystem:

<?xml version="1.0" encoding="utf-8"?> 

<id name="id" column="id" type="int">   <generator class="native" /> </id>  <property name="name" column="name" type="string" not-null="true" /> <property name="description" column="description" type="string" />  <many-to-one name="installation" column="installationid" cascade="save-update" not-null="true" /> 

classes:

the installation class is:

public class installation  {      public virtual string description { get; set; }     public virtual string name { get; set; }        public virtual ilist<computersystem> computersystems     {                  {             if (_computersystemitems== null)             {                 lock (this)                 {                     if (_computersystemitems== null)                         _computersystemitems= new list<computersystem>();                 }             }             return _computersystemitems;         }          set         {             _computersystemitems= value;          }     }      protected ilist<computersystem> _computersystemitems;         public installation()     {         description = "";         name= "";     }       } 

the computersystem class is:

public class computersystem { public virtual string name { get; set; } public virtual string description { get; set; } public virtual installation installation { get; set; }

} 

the issue error when trying delete installation contains computersystem. error is: "deleted object re-saved cascade (remove deleted object associations)". can ?

regards, seb

i think caused cascade="save-update" in mapping file computersystem. if don't need cascade in direction (child parent) may able remove it.

alternatively, try clearing installation object's computersystems list before deleting instalation.


Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -