If I have a pair of tables that have a one-to-one relation between
them, how do I control the order in which they are saved (i.e. define
which is the parent)?

Currently NHibernate keeps trying to save "Bar" before it has saved
"Foo" and thus either fails due to a foreign key violation when using
something like "guid.comb" or null key error if using something like
"native".

The mapping I have so far is listed below, the example source is at
http://gist.github.com/285899

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-
access="property" auto-import="true" default-cascade="none" default-
lazy="true">
  <class xmlns="urn:nhibernate-mapping-2.2" name="ValueMapping.Foo,
ValueMapping, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
table="`Foo`">
    <id name="Id" type="System.Int32, mscorlib, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <column name="Id" />
      <generator class="native" />
    </id>
    <one-to-one cascade="all" class="ValueMapping.Bar, ValueMapping,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
constrained="true" foreign-key="none" name="Bar" />
    <property name="Name" type="System.String, mscorlib,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <column name="Name" />
    </property>
  </class>

  <class xmlns="urn:nhibernate-mapping-2.2" name="ValueMapping.Bar,
ValueMapping, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
table="`Bar`">
    <composite-id mapped="false" unsaved-value="undefined">
      <key-many-to-one name="Foo" class="ValueMapping.Foo,
ValueMapping, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
        <column name="Foo" />
      </key-many-to-one>
    </composite-id>
    <property name="Rate" type="System.Int32, mscorlib,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <column name="Rate" />
    </property>
    <property name="Value" type="System.Int32, mscorlib,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <column name="Value" />
    </property>
  </class>
</hibernate-mapping>

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.

Reply via email to