-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Exception mit all-delete-orphan
PostPosted: Wed Jun 11, 2014 10:09 am 
Newbie

Joined: Wed Jun 11, 2014 9:57 am
Posts: 1
Hallo zusammen,
Ich arbeite derzeit mit C# und NHibernate um daten in einer MySQL Datenbank zu speichern
Ich habe derzeit eine Klasse mit mehreren Listen in deren "cascade" Eigenschaft ich auf "all-delete-orphan" konfiguriert habe. Jetzt habe bekomme ich jedesmal wenn ich ein Update auf meine Klasse ausführe folgende exception:

Code:
   An exception of type 'NHibernate.HibernateException' occurred in NHibernate.dll but was not handled in user code
   Additional information: A collection with cascade="all-delete-orphan" was no longer referenced by the owning entity instance: Darshiva.Server.Logic.Data.City.CityArtifacts


Ich weis bereits von meiner suche im Internet das ich die Liste welche von NHibernate gesetzt wird nicht ersetzen darf. Daher verwende ich die Liste welche von NHibernate gesetzt wird nur auf die folgende Weise:

Code:
    City.CityArtifacts.Clear();
    foreach (var cityArtifact in ListOfNewArtifacts)
    {
        City.CityArtifacts.Add(cityArtifact);
    }


Trotzdem bekomme ich die oben genannte Exception.

Hier ist meine Klasse mit der ich Arbeite

Code:
    public class City
    {
        public City()
        {
            ResourcesInStock = new List<ResourceAmount>();
            Buildings = new List<BuildingsWithinCityInformation>();
            PointOnMap = new MapPiece();
            Id = 0;
            Name = "City";
            Tax = 0;
            SatisfactionOfPeople = 0;
            UnitsInTraining = new List<UnitInTraining>();
            CityArtifacts = new List<CityArtifact>();
            CityEvents = new List<CityArtifact>();
        }
   
        public virtual int Id { get; set; }
        public virtual string Name { get; set; }
        public virtual MapPiece PointOnMap{ get; set; }
        public virtual IList<ResourceAmount> ResourcesInStock { get; set; }
        public virtual IList<BuildingsWithinCityInformation> Buildings { get; set; }
        public virtual IList<CityArtifact> CityArtifacts { get; set; }
        public virtual IList<CityArtifact> CityEvents { get; set; }
        public virtual double Tax { get; set; }
        public virtual double SatisfactionOfPeople { get; set; }
        public virtual double Atmosphere { get; set; }
        public virtual IList<UnitInTraining> UnitsInTraining { get; set; }
    }


Und hier das Mapping:

Code:
     <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
                       assembly="Darshiva.Server.Logic"
                       namespace="Darshiva.Server.Logic.Data">
   
      <!-- more mapping info here -->
   
      <class name="City">
        <id name="Id" type="Int32">
          <generator class="identity" />
        </id>
        <property name="Name" />
        <property name="Tax" />
        <property name="SatisfactionOfPeople" />
        <property name="Atmosphere">
          <column name="Atmosphere" default="0" />
        </property>
   
        <!--<many-to-one name="Monarch" lazy="false" class="Monarch" column="MonarchId" not-null="true" cascade="none" />-->
   
        <many-to-one name ="PointOnMap" lazy="false" class ="MapPiece" column="MapPiece" unique="true" not-null="true" cascade="none" />
       
        <list name="ResourcesInStock" cascade="all-delete-orphan" lazy="false">
          <key column="CityId" not-null="true" />
          <list-index column="ListIndex" />
          <one-to-many class="CityResource" />
        </list>
         
        <list name="UnitsInTraining" cascade="all" lazy="false">
          <key column="CityId" not-null="true" />
          <list-index column="ListIndex" />
          <one-to-many class="UnitInTraining" />
        </list>
   
        <list name="Buildings" cascade="all-delete-orphan" lazy="false">
          <key column="CityId" not-null="true" />
          <list-index column="ListIndex" />
          <one-to-many class="BuildingsWithinCityInformation" />
        </list>
   
        <list name="CityArtifacts" cascade="all-delete-orphan" lazy="false">
          <key column="CityId" not-null="true" />
          <list-index column="ListIndex" />
          <one-to-many class="CityArtifact" />
        </list>
   
        <list name="CityEvents" cascade="all" lazy="false">
          <key column="CityId" not-null="true" />
          <list-index column="ListIndex" />
          <one-to-many class="CityEvent" />
        </list>
   
      </class>
   
    </hibernate-mapping>


Was mich besonders verwirrt ist das wenn ich nur die Liste "RessourcesInStock" und "Buildings" mit der Eigenschaft "all-delete-orphan" versehe funktioniert das Update wieder und die beiden Listen verhalten sich wie erwartet.
Ich hoffe jemand von euch hat eine Idee wo das Problem liegt.
Vielen dank schon einmal für eure Hilfe.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.