I can try taking a look at it this weekend (although fair warning, pretty
packed set of days coming up...) and see what I can do. The workaround
involves adding the PolicyNumber column to your table twice. Once for actual
use by the compositeId, and the second time for use as the property. Then
keep them synchronized in your domain model. Now you can use a property-ref.

Ugly. As. Sin. But it should work.

On Fri, Jan 29, 2010 at 11:53 AM, Corey Coogan <[email protected]>wrote:

> I've heard nothing from NHUSERS group on how to resolve this.  I'd be
> interested in hearing your workaround of mapping PolicyNumber twice.
> It sounds ugly, but perhaps the only option.  I can't quite figure out
> how to do this though?
>
> On Jan 26, 10:38 am, Corey Coogan <[email protected]> wrote:
> > Thanks Hudson.  I actually posed the question to NHUsers right after
> > my last reply here.  When I find something out, I'll share here.  The
> > DB can't be changed.  It's legacy and has an entire insurance company
> > running expecting that primary key.  The brass here won't even
> > consider it.  Thanks for asking though.  I am a huge anti-fan of
> > composite keys as well.
> >
> > Corey
> >
> > On Jan 26, 9:09 am, Hudson Akridge <[email protected]> wrote:
> >
> > > It's no different. Your problem isn't a FNH problem, it's an NH
> problem.
> > > Also, you may be able to head over to the nhusers
> > > <http://groups.google.com/group/nhusers>google group and ask your
> question
> > > there, they have more experience solving strange edge case scenario's.
> If
> > > they can figure it out and get you the xml for it, then we can figure
> out
> > > the FNH versions of those xml elements.
> >
> > > The only workaround I can think of involves mapping the PolicyNumber
> column
> > > twice on the parent table, which is an awful workaround imo (But that
> would
> > > allow you to map PolicyNumber as the second property). Is there any way
> we
> > > can change the DB schema to move away from CompositeId's (Probably not,
> but
> > > figured I'd ask)?
> >
> > > On Tue, Jan 26, 2010 at 8:46 AM, Corey Coogan <[email protected]>
> wrote:
> > > > Thanks for the help here Hudson.  I appreciate your continued
> support.
> >
> > > > How would this be possible from an XML mapping strategy?
> >
> > > > On Jan 25, 4:28 pm, Hudson Akridge <[email protected]> wrote:
> > > > > Can't have two properties mapped to the same field in NHibernate.
> That's
> > > > the
> > > > > index out of range exception. It's expecting there to be n columns,
> but
> > > > > there's really n-1 columns (for the repeat).
> >
> > > > > I'm in the middle of a bunch of non-FNH related stuff atm (also
> known as
> > > > day
> > > > > job), but let me think on this and see what we can do about getting
> > > > around
> > > > > this. We should be very close to resolving the issue. I was hoping
> the
> > > > none
> > > > > modifier for access would prevent NHibernate from attempting to
> include
> > > > the
> > > > > column in the query a second time. Guess not. More thoughts later.
> >
> > > > > On Mon, Jan 25, 2010 at 3:50 PM, Corey Coogan <
> [email protected]>
> > > > wrote:
> > > > > > This is almost working.  At least I can build the sessionfactory
> now.
> > > > > > My tests against SqlLite are failing though. Thanks for all your
> help.
> >
> > > > > > Details below:
> >
> > > > > > --------------------------
> > > > > > Relevant Mapping
> > > > > > --------------------------
> > > > > >  mapping.Map(x => x.PolicyNumberMapping,
> "POLICY_NUMBER").Access.None
> > > > > > ();
> >
> > > > > >            mapping.HasMany(x => x.CreditCards)
> > > > > >                .KeyColumn("POL_NBR")
> > > > > >                .PropertyRef("PolicyNumberMapping");
> >
> > > > > > - <composite-id mapped="false" unsaved-value="undefined">
> > > > > > - <key-property name="PolicyNumber" type="System.String,
> mscorlib,
> > > > > > Version=2.0.0.0, Culture=neutral,
> PublicKeyToken=b77a5c561934e089">
> > > > > >  <column name="`POLICY_NUMBER`" />
> > > > > >  </key-property>
> > > > > > - <key-property name="PolicyDateTime" type="System.Nullable`1
> > > > > > [[System.DateTime, mscorlib, Version=2.0.0.0, Culture=neutral,
> > > > > > PublicKeyToken=b77a5c561934e089]], mscorlib, Version=2.0.0.0,
> > > > > > Culture=neutral, PublicKeyToken=b77a5c561934e089">
> > > > > >  <column name="`POLICY_DATE_TIME`" />
> > > > > >  </key-property>
> > > > > >  </composite-id>
> > > > > > - <property access="none" name="PolicyNumberMapping"
> > > > > > type="System.String, mscorlib, Version=2.0.0.0, Culture=neutral,
> > > > > > PublicKeyToken=b77a5c561934e089">
> > > > > >  <column name="`POLICY_NUMBER`" />
> > > > > >  </property>
> >
> > > > > > -----------------------
> > > > > > ERROR
> > > > > > -----------------------
> > > > > > Test method
> >
> > > >
> NHibernate.Spike.Test.Unit.Mappings.When_policy_is_mapped.Can_map_policy
> > > > > > threw exception:  System.ArgumentOutOfRangeException: Index was
> out of
> > > > > > range. Must be non-negative and less than the size of the
> collection.
> > > > > > Parameter name: index.
> > > > > > at System.ThrowHelper.ThrowArgumentOutOfRangeException
> > > > > > (ExceptionArgument argument, ExceptionResource resource)
> > > > > > at System.ThrowHelper.ThrowArgumentOutOfRangeException()
> > > > > > at System.Collections.Generic.List`1.get_Item(Int32 index)
> > > > > > at
> System.Data.SQLite.SQLiteParameterCollection.GetParameter(Int32
> > > > > > index)
> > > > > > at
> >
> > > >
> System.Data.Common.DbParameterCollection.System.Collections.IList.get_Item
> > > > > > (Int32 index)
> > > > > > at NHibernate.Type.DateTimeType.Set(IDbCommand st, Object value,
> Int32
> > > > > > index)
> > > > > > at NHibernate.Type.NullableType.NullSafeSet(IDbCommand cmd,
> Object
> > > > > > value, Int32 index)
> > > > > > at NHibernate.Type.NullableType.NullSafeSet(IDbCommand st, Object
> > > > > > value, Int32 index, ISessionImplementor session)
> > > > > > at NHibernate.Type.ComponentType.NullSafeSet(IDbCommand st,
> Object
> > > > > > value, Int32 begin, ISessionImplementor session)
> > > > > > at NHibernate.Persister.Entity.AbstractEntityPersister.Dehydrate
> > > > > > (Object id, Object[] fields, Object rowId, Boolean[]
> includeProperty,
> > > > > > Boolean[][] includeColumns, Int32 table, IDbCommand statement,
> > > > > > ISessionImplementor session, Int32 index)
> > > > > > at
> NHibernate.Persister.Entity.AbstractEntityPersister.Insert(Object
> > > > > > id, Object[] fields, Boolean[] notNull, Int32 j, SqlCommandInfo
> sql,
> > > > > > Object obj, ISessionImplementor session)
> > > > > > at
> NHibernate.Persister.Entity.AbstractEntityPersister.Insert(Object
> > > > > > id, Object[] fields, Object obj, ISessionImplementor session)
> > > > > > at NHibernate.Action.EntityInsertAction.Execute()
> > > > > > at NHibernate.Engine.ActionQueue.Execute(IExecutable executable)
> > > > > > at NHibernate.Engine.ActionQueue.ExecuteActions(IList list)
> > > > > > at NHibernate.Engine.ActionQueue.ExecuteActions()
> > > > > > at
> >
> > > >
> NHibernate.Event.Default.AbstractFlushingEventListener.PerformExecutions
> > > > > > (IEventSource session)
> > > > > > at NHibernate.Event.Default.DefaultFlushEventListener.OnFlush
> > > > > > (FlushEvent event)
> > > > > > at NHibernate.Impl.SessionImpl.Flush()
> > > > > > at NHibernate.Transaction.AdoTransaction.Commit()
> > > > > > at
> >
> > > >
> NHibernate.Spike.Test.Unit.Mappings.When_policy_is_mapped.Can_map_policy
> > > > > > () in
> >
> > > > > > On Jan 21, 4:03 pm, Hudson Akridge <[email protected]>
> wrote:
> > > > > > > We are deep in NHibernate magic territory :) If that still
> doesn't
> > > > work
> > > > > > for
> > > > > > > you, I'll see what I can do about setting up a test environment
> to
> > > > what
> > > > > > > you've got and giving it a go. It's an interesting problem, and
> I'd
> > > > like
> > > > > > to
> > > > > > > know what the final solution will be. My knowledge in this area
> is
> > > > purely
> > > > > > > theoretical ;)
> >
> > > > > > > On Thu, Jan 21, 2010 at 4:00 PM, Corey Coogan <
> [email protected]
> >
> > > > > > wrote:
> > > > > > > > I'll give that a try tomorrow.
> >
> > > > > > > > Thanks,
> > > > > > > > Corey
> >
> > > > > > > > On Jan 21, 2:45 pm, Hudson Akridge <[email protected]
> >
> > > > wrote:
> > > > > > > > > Ah, that might make sense actually. Because you technically
> don't
> > > > > > have
> > > > > > > > > PolicyNumber mapped as a property, it's part of your
> composite
> > > > key.
> > > > > > Try
> > > > > > > > > something like this:
> > > > > > > > > Map(x=> PolicyNumberForNH, "PolicyNumber").Access.None();
> >
> > > > > > > > > Then change your property-ref to PolicyNumberForNH and see
> if
> > > > > > NHibernate
> > > > > > > > > gets the clue then. I believe it actually needs a
> <property> to
> > > > map a
> > > > > > > > > property-ref to, and not just a POCO property.
> >
> > > > > > > > > On Thu, Jan 21, 2010 at 2:26 PM, Corey Coogan <
> > > > [email protected]
> >
> > > > > > > > wrote:
> > > > > > > > > > I spoke too soon.  My claim that it worked was a case of
> > > > mistaken
> > > > > > > > > > identity on a test that was being run but recently
> changed.
> >
> > > > > > > > > > Here's what this syntax is producing in an HBM.
> >
> > > > > > > > > > - <bag cascade="save-update" name="CreditCards"
> mutable="true">
> > > > > > > > > > - <key property-ref="PolicyNumber">
> > > > > > > > > >  <column name="`PolNbr`" />
> > > > > > > > > >  </key>
> > > > > > > > > >  <one-to-many
> class="Aah.Policy.InfoLayer.CrdtCardAcctRecord,
> > > > > > > > > > NHibernate.Spike.Data, Version=1.0.0.0, Culture=neutral,
> > > > > > > > > > PublicKeyToken=null" />
> > > > > > > > > >  </bag>
> >
> > > > > > > > > > I don't think that is right?  I get an error during
> > > > configuration
> > > > > > from
> > > > > > > > > > NH that it can't find property PolicyNumber on my Policy
> object
> > > > > > > > > > (Parent class to CreditCards).  That message is very
> misleading
> > > > and
> > > > > > > > > > led to hours of chasing the wrong stuff.
> >
> > > > > > > > > > On Jan 20, 11:41 am, Hudson Akridge <
> [email protected]>
> > > > > > wrote:
> > > > > > > > > > > Awesome, glad to be of assistance :)
> >
> > > > > > > > > > > On Wed, Jan 20, 2010 at 11:40 AM, Corey Coogan <
> > > > > > > > [email protected]
> > > > > > > > > > >wrote:
> >
> > > > > > > > > > > > This worked like a charm and is exactly what I
> needed.
> >
> > > > > > > > > > > > Thanks again!
> >
> > > > > > > > > > > > On Jan 20, 9:34 am, Hudson Akridge <
> > > > [email protected]>
> > > > > > > > wrote:
> > > > > > > > > > > > > Understood. Ok, well, let's see if this works:
> > > > > > > > > > > > > HasMany(x=>
> >
> > > > > >
> x.CreditCards).AsBag().KeyColumn("PolNbr").PropertyRef("PolicyNumber");
> >
> > > > > > > > > > > > > The PropertyRef should allow you to map to a
> non-key
> > > > column
> > > > > > in
> > > > > > > > the
> > > > > > > > > > parent
> > > > > > > > > > > > > table. On the References() side it allows you to
> map to a
> > > > non
> > > > > > key
> > > > > > > > > > > > property
> > > > > > > > > > > > > in the related table. PropertyRef is for mapping
> lagacy
> > > > data
> > > > > > > > > > > > specifically.
> >
> > > > > > > > > > > > > If that doesn't work, do a quick ExportTo() in your
> > > > config
> > > > > > and
> > > > > > > > paste
> > > > > > > > > > the
> > > > > > > > > > > > > hbm.xml mappings if you could, so I can make sure
> FNH is
> > > > > > writing
> > > > > > > > the
> > > > > > > > > > > > correct
> > > > > > > > > > > > > XML.
> >
> > ...
> >
> > read more ยป
>
> --
> You received this message because you are subscribed to the Google Groups
> "Fluent NHibernate" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<fluent-nhibernate%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/fluent-nhibernate?hl=en.
>
>


-- 
- Hudson
http://www.bestguesstheory.com
http://twitter.com/HudsonAkridge

-- 
You received this message because you are subscribed to the Google Groups 
"Fluent NHibernate" 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/fluent-nhibernate?hl=en.

Reply via email to