I have 2 classes (bpbSubmissionContainer and bpbSubmission) mapped as joined subclass (mapping below):
<class name="bo.bpbSubmissionContainer" table="bpb_baselines_t">
<id name="Id" type="Int32" column="bpb_baselines_t_id" unsaved-value="0">
<generator class="identity" />
<!--
<generator class="sequence">
<param name="sequence">bpb_projects_t_seq</param>
</generator>
-->
</id>
<property name="baselinedate" type="Nullables.NHibernate.NullableDateTimeType, Nullables.NHibernate">
<column name="baseline_date" unique-key="baselinedateproject"></column>
</property>
<many-to-one name="project" class=".bo.bpbProject, ">
<column name="bpb_projects_t_id" unique-key="baselinedateproject"></column>
</many-to-one>
<property name="updateddt" column="updated_dt" type="Nullables.NHibernate.NullableDateTimeType, Nullables.NHibernate" />
<property name="createby" column="create_by" type="Nullables.NHibernate.EmptyStringType,Nullables.NHibernate" />
<property name="createdt" column="create_dt" type="Nullables.NHibernate.NullableDateTimeType, Nullables.NHibernate" />
<property name="updatedby" column="updated_by" type="Nullables.NHibernate.EmptyStringType,Nullables.NHibernate" />
<joined-subclass name="bo.bpbSubmission, " table="bpb_submissions_t">
<key>
<column name="bpb_submissions_t_id" unique="true"/>
</key>
<property name="collabdocid" column="collab_doc_id" type="Nullables.NHibernate.NullableInt32Type, Nullables.NHibernate" />
<property name="submissiondate" column="submission_date" type="Nullables.NHibernate.NullableDateTimeType, Nullables.NHibernate"
not-null="true" />
<property name="isaccurate" column="is_accurate" type="Nullables.NHibernate.NullableBooleanType, Nullables.NHibernate" />
<property name="isontime" column="is_ontime" type="Nullables.NHibernate.NullableBooleanType, Nullables.NHibernate" />
<property name="note" column="note" type="Nullables.NHibernate.EmptyStringType,Nullables.NHibernate" />
<property name="createby" column="create_by" type="Nullables.NHibernate.EmptyStringType,Nullables.NHibernate" />
<property name="createdt" column="create_dt" type="Nullables.NHibernate.NullableDateTimeType, Nullables.NHibernate" />
<property name="updatedby" column="updated_by" type="Nullables.NHibernate.EmptyStringType,Nullables.NHibernate" />
<property name="updateddt" column="updated_dt" type="Nullables.NHibernate.NullableDateTimeType, Nullables.NHibernate" />
</joined-subclass>
</class>
I have created and saved object bpbSubmissionContainer, but now I would like to save the same object as a child object: bpbSubmission.
SaveOrUpdate() give a NHibernate.StaleObjectStateException because nhibernate try to perform 2 updates (but hte 2nd update against bpbsubmission off course fails since no record exists yet)
The only things that seem to work are:
1. copying all data to B, delete A and save B. (not very useful because it creates a new id)
2. using native sql to insert id from A into B
Is there a way to do this in a "normal hibernate" style?
|