Dears,
we got a big trouble on persisting domain object under parent/child relationships. the error message was:NHibernate: Collection was modified; enumeration operation may not execute.
pls help to review the stuffs, thanks.
(1) mapping file:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name=Orgnization, BizModel" table="OGNZ" proxy="IOrgnization, BizModel">
<id name="EntityId" type="string" unsaved-value="null">
<column name="OrgId" sql-type="integer" not-null="true" unique="true"/>
<generator class="native"/>
</id>
...
<many-to-one name="ParentUnit" class="Orgnization, BizModel" unique="true">
<column name="ParentOrgId" sql-type="int"/>
</many-to-one>
<bag name="SubUnits" cascade="save-update" inverse="true" lazy="true" order-by="OrgCode">
<key column="ParentOrgId"/>
<one-to-many class="Orgnization, BizModel"/>
</bag>
</class>
</hibernate-mapping>
(2) code
Code:
IOrgnization oParentDept = _orgnizationRepository.GetOrgnizationByCode("GM");
IEmployee oBoss = _employeeRepository.GetByEmployeeNo("E000001");
IOrgnization oDept = _bizEntityFactory.CreateEntityInstance<IOrgnization>() as IOrgnization;
oDept.Code = "GM01";
oDept.Name = "GM Sub 01";
oDept.ParentUnit = oParentDept;
oDept.Boss = oBoss;
_orgnizationRepository.Save(oDept);