*************************UPDATE***************************
I understood the problem myself, I was using serialized DomainModel objects. This means that the objects sent by value instead of reference using remoting. So, the objects id were not updated when inserted.
So, there was no problem with NHibernate.
***********************************************************
Hello,
I'm using NHibernate with remoting and get strange behaviour.
I use a Repository class that encapsulates a session and for each remote call I build a new session and do either SaveOrUpdate or some query.
I have a class "ErrorType" with children "ActionPlanConnectors". When I insert a new "ActionPlanConnector" everthing works fine. But when I update the "ActionPlanConnector" in a subsequent call NHibernate is both updating and inserting my "ActionPlanConnectors" leaving two posts with the same info.
When I use the Repository class locally, without remoting, I have no problem. NHibernate works perfectly. The problem only occurs with remoting.
This is my hbm file:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="DomainModel.ErrorType, DomainModel"
lazy ="false"
dynamic-update="true"
dynamic-insert="true"
select-before-update="true"
table="ERR_TYPES">
<id name="Id" access="field.camelcase-underscore" column="ID" type="Int32" unsaved-value="0" length="4">
<generator class="native" />
</id>
<property name="SequenceNo" column="SEQUENCE_NO" access="field.camelcase-underscore" type="Int32" />
<property name="Damage" column="DAMAGE" access="field.camelcase-underscore" type="Boolean" />
<property name="ActionCode" column="ACTION_CODE" access="field.camelcase-underscore" type="Boolean" />
<property name="RealEstate" column="REAL_ESTATE" access="field.camelcase-underscore" type="Boolean" />
<property name="WorkOrder" column="WORK_ORDER" access="field.camelcase-underscore" type="Boolean" />
<property name="EmergencyAlarm" column="EMERGENCY_ALARM" access="field.camelcase-underscore" type="Boolean" />
<property name="Description" column="DESCRIPTION" access="field.camelcase-underscore" type="AnsiString" not-null="true" length="100"/>
<bag name="ErrorTypeDetails"
access="field.camelcase-underscore"
lazy ="false"
table="REL_DETAIL_TYPE"
inverse="false">
<key column="TYPE_ID"/>
<many-to-many class ="DomainModel.ErrorTypeDetail, Kopplet.DomainModel" >
<column name="DETAIL_ID" />
</many-to-many>
</bag>
<bag name="ActionPlanConnectors"
access="field.camelcase-underscore"
lazy ="false"
table="REL_ACTION"
cascade="all-delete-orphan"
inverse="false">
<key column="ERR_TYPE_ID"/>
<one-to-many class="DomainModel.ActionPlanConnector, Kopplet.DomainModel" />
</bag>
</class>
</hibernate-mapping>
Any help would be greatly apreciated.
Thanks!
Martin
|