The foreign key generator is not documented and it’s not readily obvious how to 
implement it.

      <generator class="foreign">
        <param name="property">Foo</param>
      </generator>
      ...
      <one-to-many name="Foo" />

See 
http://weblogs.asp.net/ricardoperes/archive/2009/06/10/nhibernate-mappings.aspx 
for an example.

From: Fabio Maulo 
Sent: Wednesday, October 27, 2010 3:35 PM
To: [email protected] 
Subject: Re: [nhusers] Re: How to map a class and a composite with multiple 
sub-types to the same database table?

5.1.4.1. generator
The required <generator> child element names a .NET class used to generate 
unique identifiers for instances of the persistent class. 



On Wed, Oct 27, 2010 at 1:05 PM, [email protected] 
<[email protected]> wrote:

  Fabio,

  I appreciate your insights. I will be sure to add one of the
  NHibernate books to my reading list. When I first began using
  NHibernate 1.2 (yes I know this is an older version), I read the docs
  end to end.

  I looked at the link you provided above,
  http://nhforge.org/doc/nh/en/index.html#mapping-declaration-id, and it
  made no mention of how to use <generator class="foreign">

  In the meantime, I am simply trying to avoid creating an entirely new
  table for essentially one field. Due to my admittedly inadequate grasp
  of this particular problem, I may to have to do just that.

  I will try generating the schema from the mapping file to see if that
  provides any help.

  Thanks,

  Robert


  On Oct 26, 5:57 pm, Fabio Maulo <[email protected]> wrote:
  > IMO you are using a "try-catch" technique to study how work with 
NHibernate.http://nhforge.org/doc/nh/en/index.html#mapping-declaration-id
  >

  > <http://nhforge.org/doc/nh/en/index.html#mapping-declaration-id>in 
additionhttp://nhforge.org/content/Books.aspx

  >
  > <http://nhforge.org/content/Books.aspx>btw try to create the DB using
  > NHibernate and then check the differences.
  > Configuration cfg = ....;
  > new SchemaExport(cfg).Create(false, true);
  >

  > On Tue, Oct 26, 2010 at 4:20 PM, mailto:[email protected] <

  >
  >
  >
  > [email protected]> wrote:
  > > If I remove
  >
  > > <generator class="foreign">
  > >       <param name="property">structural</param>
  > >     </generator>
  >
  > > it gives an error:
  >
  > > The element 'id' in namespace 'urn:nhibernate-mapping-2.2' has
  > > incomplete content. List of possible elements expected:
  > > 'urn:nhibernate-mapping-2.2:meta urn:nhibernate-mapping-2.2:column
  > > urn:nhibernate-mapping-2.2:generator'.
  >
  > > How do I fix this?
  >
  > > Thanks,
  >
  > > Robert
  >
  > > On Oct 26, 1:56 pm, Fabio Maulo <[email protected]> wrote:
  > > > It is available btw with
  > > > <generator class="foreign">
  > > >        <param name="property">structural</param>
  > > >      </generator>
  > > > you are saying to NH that he must assign the ID and, probably, you have
  > > an
  > > > identity in the Structural table.
  >
  > > > On Tue, Oct 26, 2010 at 3:46 PM, [email protected] <
  >
  > > > mailto:[email protected]> wrote:
  > > > > No, I'm not generating the database with NHibernate. Not completely
  > > > > sure that feature was available in version 1.2.
  >
  > > > > Thanks,
  >
  > > > > Robert
  >
  > > > > On Oct 26, 1:32 pm, Fabio Maulo <[email protected]> wrote:
  > > > > >   <generator class="foreign">
  > > > > >        <param name="property">structural</param>
  > > > > >      </generator>
  >
  > > > > > are you generating the DB using NH ?
  >
  > > > > > On Tue, Oct 26, 2010 at 3:17 PM, [email protected] <
  >
  > > > > > [email protected]> wrote:
  > > > > > > When trying to map a class and a composite with multiple sub-types
  > > to
  > > > > > > the same table, I get the error "Cannot insert explicit value for
  > > > > > > identity column in table 'Structural' when IDENTITY_INSERT is set
  > > to
  > > > > > > OFF." when attempting to create an instance of "Structural" that
  > > > > > > pertains to the mapping file below. I am using NHibernate 1.2 if 
it
  > > > > > > matters. I found the following article that suggest this type of
  > > > > > > mapping is possible:
  >
  > >http://colinjack.blogspot.com/2008/03/nhibernate-working-around-lack-.
  > > > > ..
  >
  > > > > > > <?xml version="1.0" encoding="utf-8" ?>
  > > > > > > <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
  > > > > > >        <class name="Esl.Domain.Buildings.Structural, Esl.Domain"
  > > > > > > table="Structural">
  > > > > > >    <id name="id" access="field" column="Id">
  > > > > > >      <generator class="native" />
  > > > > > >    </id>
  > > > > > >                <property name="isDirty" column="IsDirty"
  > > > > access="field"/>
  > > > > > >                <property name="solarHeatGain"
  > > column="SolarHeatGain"
  > > > > > > access="field" type="Nullables.NHibernate.NullableDoubleType,
  > > > > > > Nullables.NHibernate" />
  > > > > > >                <property name="wallCavityInsulation"
  > > > > > > column="WallCavityInsulation"
  > > > > > > access="field" type="Nullables.NHibernate.NullableDoubleType,
  > > > > > > Nullables.NHibernate" />
  > > > > > >                <property name="wallContinuousInsulation"
  > > > > > > column="WallContinuousInsulation"  access="field"
  > > > > > > type="Nullables.NHibernate.NullableDoubleType,
  > > Nullables.NHibernate" /
  >
  > > > > > >                <property name="wallExteriorFinish"
  > > > > > > column="WallExteriorFinish"
  > > > > > > access="field" />
  > > > > > >                <property name="uValue" column="UValue"
  > >  access="field"
  > > > > > > type="Nullables.NHibernate.NullableDoubleType,
  > > Nullables.NHibernate" /
  >
  > > > > > >                <property name="numberOfBedrooms"
  > > > > column="NumberOfBedrooms"
  > > > > > > access="field" type="Nullables.NHibernate.NullableInt32Type,
  > > > > > > Nullables.NHibernate" />
  > > > > > >                <many-to-one name="roof" access="field"
  > > cascade="all"
  > > > > > > class="Esl.Domain.Buildings.Roof, Esl.Domain" column="RoofId" />
  >
  > > > > > >    <one-to-one name="foundation" access="field"
  > > cascade="all-delete-
  > > > > > > orphan" />
  >
  > > > > > >    <list access="field" name="floors" table="Floors" cascade="all-
  > > > > > > delete-orphan">
  > > > > > >                        <key column="StructuralId" />
  > > > > > >                        <index column="Position" />
  > > > > > >                        <one-to-many
  > > class="Esl.Domain.Buildings.Floor,
  > > > > > > Esl.Domain"/>
  > > > > > >                </list>
  > > > > > >        </class>
  >
  > > > > > >  <class name="Esl.Domain.Buildings.Foundation, Esl.Domain"
  > > > > > > table="Structural" discriminator-value="-1">
  >
  > > > > > >    <id name="id" access="field" column="Id">
  > > > > > >      <!--This lets us get away breaking out Foundation into a 
class
  > > > > > > mapping without
  > > > > > >        creating another database table or a database migration-->
  > > > > > >      <generator class="foreign">
  > > > > > >        <param name="property">structural</param>
  > > > > > >      </generator>
  > > > > > >    </id>
  > > > > > >    <discriminator column="FoundationType" type="integer" />
  >
  > > > > > >    <property name="isDirty" column="FoundationIsDirty"
  > > access="field"/
  >
  > > > > > >    <property name="insulation" column="FloorOrSlabInsulation"
  > > > > > > access="field" type="Nullables.NHibernate.NullableDoubleType,
  > > > > > > Nullables.NHibernate" />
  >
  > > > > > >    <one-to-one constrained="true" name="structural"
  > > access="field"/>
  >
  > > > > > >    <subclass name="Esl.Domain.Buildings.SlabFoundation, 
Esl.Domain"
  > > > > > >              discriminator-value="0"/>
  > > > > > >    <subclass name="Esl.Domain.Buildings.PilingFoundation,
  > > Esl.Domain"
  > > > > > >              discriminator-value="1"/>
  > > > > > >    <subclass name="Esl.Domain.Buildings.PierAndBeamFoundation,
  > > > > > > Esl.Domain"
  > > > > > >              discriminator-value="2"/>
  > > > > > >    <subclass 
name="Esl.Domain.Buildings.ConditionedBelowFoundation,
  > > > > > > Esl.Domain"
  > > > > > >              discriminator-value="3"/>
  > > > > > >  </class>
  > > > > > > </hibernate-mapping>
  >
  > > > > > > Any help would be greatly appreciated.
  >
  > > > > > > Thanks,
  >
  > > > > > > Robert
  >
  > > > > > > --
  > > > > > > 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
  > > > > > > 
mailto:nhusers%[email protected]<mailto:nhusers%[email protected]>
  > > 
<mailto:nhusers%[email protected]<mailto:nhusers%[email protected]>
  >
  > > > > 
<mailto:nhusers%[email protected]<mailto:nhusers%[email protected]>

  > > 
<mailto:nhusers%[email protected]<mailto:nhusers%[email protected]>

  >
  > > > > > > .
  > > > > > > For more options, visit this group at
  > > > > > >http://groups.google.com/group/nhusers?hl=en.
  >
  > > > > > --
  > > > > > Fabio Maulo
  >
  > > > > --
  > > > > 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
  > > > > 
mailto:nhusers%[email protected]<mailto:nhusers%[email protected]>
  > > 
<mailto:nhusers%[email protected]<mailto:nhusers%[email protected]>
  >
  > > > > .
  > > > > For more options, visit this group at
  > > > >http://groups.google.com/group/nhusers?hl=en.
  >
  > > > --
  > > > Fabio Maulo
  >
  > > --
  > > 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
  > > 
mailto:nhusers%[email protected]<mailto:nhusers%[email protected]>
  > > .
  > > For more options, visit this group at
  > >http://groups.google.com/group/nhusers?hl=en.
  >
  > --
  > Fabio Maulo

  --
  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 
mailto:nhusers%[email protected].
  For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.





-- 
Fabio Maulo

-- 
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.

-- 
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