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.  [ 2 posts ] 
Author Message
 Post subject: Found shared references to a collection
PostPosted: Mon Mar 05, 2007 6:03 am 
Beginner
Beginner

Joined: Tue Sep 19, 2006 11:26 am
Posts: 33
I am getting the following exception : NHibernate.HibernateException : Found shared references to a collection

The mapping file for Organisation is:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">

  <class name="Services.BusinessEntities.Organisation,Services.BusinessEntities" table="Organisation">

      <id name="Id" column="id" type="Int64" unsaved-value="0">
         <generator class="identity"/>
      </id>
      <bag name="ContactList" inverse="true" lazy="true" >
         <key column="empOrganisationId" />
         <one-to-many class="Services.BusinessEntities.Contact,Services.BusinessEntities" />
      </bag>
    <bag name="ContactConflictList" inverse="true" lazy="true" >
      <key column="organisationId" />
      <one-to-many class="Services.BusinessEntities.ContactConflict,Services.BusinessEntities" />
    </bag>
    <bag name="OrganisationAddressList" inverse="false" lazy="true" cascade="all-delete-orphan">
      <key column="organisationId" />
      <one-to-many class="Services.BusinessEntities.OrganisationAddress,Services.BusinessEntities" />
    </bag>   
      <bag name="Org2PartnershipList" inverse="true" lazy="true" cascade="all-delete-orphan">
         <key column="org2Id" />
         <one-to-many class="Services.BusinessEntities.OrganisationPartnership,Services.BusinessEntities" />
      </bag>
      <bag name="Org1PartnershipList" inverse="true" lazy="true" cascade="all-delete-orphan">
         <key column="org1Id" />
         <one-to-many class="Services.BusinessEntities.OrganisationPartnership,Services.BusinessEntities" />
      </bag>
      <property column="name" type="String" name="Name" not-null="true" length="50" />
    <property column="alternateName" type="String" name="AlternateName" not-null="true" length="50" />
      <property column="sortName" type="String" name="SortName" not-null="true" length="50" />
    <property column="externalCode" type="String" name="ExternalCode" not-null="true" length="50" />
      <property column="isSupplier" type="Boolean" name="IsSupplier" not-null="true" />
    <property column="isSubscriber" type="Boolean" name="IsSubscriber" not-null="true" />
    <property column="isInactive" type="Boolean" name="IsInactive" not-null="true" />
    <many-to-one name="OrganisationType" column="organisationTypeId" class="Services.BusinessEntities.OrganisationType,Services.BusinessEntities" />
    <many-to-one name="FundingBody" column="fundingBodyId" class="Services.BusinessEntities.FundingBody,Services.BusinessEntities" />
  </class>
</hibernate-mapping>


The mapping file for OgranisationPartnership is:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
   <class name="Services.BusinessEntities.OrganisationPartnership,Services.BusinessEntities" table="OrganisationPartnership">

      <id name="Id" column="id" type="Int64">
         <generator class="identity"/>
      </id>
      <many-to-one name="Org1" column="org1Id" class="Services.BusinessEntities.Organisation,Services.BusinessEntities" />
      <many-to-one name="Org2" column="org2Id" class="Services.BusinessEntities.Organisation,Services.BusinessEntities" />
      <many-to-one name="OrgPartnershipType" column="orgPartnershipTypeId" class="Services.BusinessEntities.OrganisationPartnershipType,Services.BusinessEntities" />
      <property column="descr" type="String" name="Descr" not-null="true" length="50" />
      <property column="isInactive" type="Boolean" name="IsInactive" not-null="true" />
      
   </class>
</hibernate-mapping>


As you can see from the mapping files, we have the concept of an organisation partnership and a partnership consists of two organisations. Therfore there is a many to one realtionship from the org1 column of the OrgnisationPartnership entity and from the org2 column.

It seems to be this that is causing me the problem. When I pass an organisation to session.SaveOrUpdateCopy, I get this exception. If I remove one of the organisation list bags from the organisation mapping file, the exception goes away - I need to have this relationship however so that any updates to the parternship are saved when I save an oganisation.

I am using NHibernate version 1.2.0.

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 05, 2007 8:36 am 
Beginner
Beginner

Joined: Tue Sep 19, 2006 11:26 am
Posts: 33
I've discovered what was causing my problem. The Org1PartnershipList and Org2PartnershipList properties both refered to the same member variable:
Code:
      public virtual IList Org1PartnershipList
      {
         get { return org1PartnershipList; }
         set { org1PartnershipList = value; }
      }

      public virtual IList Org2PartnershipList
      {
         get { return org1PartnershipList; }
         set { org1PartnershipList = value; }
      }


Changing org1PartnershipList to org2PartnershipList in the geter and setter for Org2PartnershipList, resolved my problem.

Next time I will taking more care when editing the output from the mapping generation tool I use!!! ;o)


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

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.