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.