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 <hudson.akri...@gmail.com> 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 <coreycoo...@yahoo.com> 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 <hudson.akri...@gmail.com> 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 <coreycoo...@yahoo.com>
> > wrote:
> > > > I'll give that a try tomorrow.
>
> > > > Thanks,
> > > > Corey
>
> > > > On Jan 21, 2:45 pm, Hudson Akridge <hudson.akri...@gmail.com> 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 <coreycoo...@yahoo.com
>
> > > > 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 <hudson.akri...@gmail.com>
> > wrote:
> > > > > > > Awesome, glad to be of assistance :)
>
> > > > > > > On Wed, Jan 20, 2010 at 11:40 AM, Corey Coogan <
> > > > coreycoo...@yahoo.com
> > > > > > >wrote:
>
> > > > > > > > This worked like a charm and is exactly what I needed.
>
> > > > > > > > Thanks again!
>
> > > > > > > > On Jan 20, 9:34 am, Hudson Akridge <hudson.akri...@gmail.com>
> > > > 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.
>
> > > > > > > > > You're fortunate that you're going from Composite to a single
> > id,
> > > > and
> > > > > > not
> > > > > > > > > the other way around. NHibernate doesn't support Hibernate's
> > > > > > <properties>
> > > > > > > > > tag yet, which means you can only map from one column to
> > another
> > > > > > > > (hibernate
> > > > > > > > > allows you to do many columns to many columns in a
> > property-ref)
>
> > > > > > > > > On Tue, Jan 19, 2010 at 8:59 PM, Corey Coogan <
> > > > coreycoo...@yahoo.com
>
> > > > > > > > wrote:
> > > > > > > > > > Thanks again Hudson.  I'm totally with you on the DB stuff
> > and
> > > > have
> > > > > > > > > > read quite a bit on the relationships. Unfortunately, most
> > the
> > > > > > tables
> > > > > > > > > > truly need a PolicyNumber and PolicyDate as the composite
> > key.
> > > > > >  That's
> > > > > > > > > > because everytime a policy is renewed or changed in any
> > way, a
> > > > new
> > > > > > > > > > "portfolio" gets created which is a whole mess of tables
> > with
> > > > those
> > > > > > 2
> > > > > > > > > > columns used to identify them.  On the other hand,
> > something
> > > > like
> > > > > > > > > > CreditCard, is tied to a policy regardless of it's
> > portfolio,
> > > > so in
> > > > > > > > > > this case it is related to a PolicyNumber only.
>
> > > > > > > > > > I realized that the keys typically match up as a
> > traditional
> > > > > > foreign
> > > > > > > > > > key constraint, but that's not the way these two tables are
> > > > > > related,
> > > > > > > > > > which is why I'm posting this question.  These are tied
> > > > together
> > > > > > today
> > > > > > > > > > with a hand-rolled data access layer.  The user specifies a
> > > > > > > > > > policynumber and an as of date and the following queries
> > are
> > > > > > executed
> > > > > > > > > > on a single open connection:
>
> > > > > > > > > > - Get the max(policydate) <= asOfDate
> > > > > > > > > > - Ge the Policy record for the PolicyNumber/PolicyDate
> > > > > > > > > > - Get credit cards for the PolicyNumber
>
> > > > > > > > > > I'm OK with specifiying a hand-written sql statement if
> > > > necessary.
> > > > > > > > > > Maybe I need to handle these cases where there is no real
> > FK in
> > > > the
> > > > > > > > > > database by populating with an NH query after the initial
> > > > > > retrieval.
> > > > > > > > > > I'm just looking for the best way to map this stuff despite
> > the
> > > > > > ugly
> > > > > > > > > > nature of what I'm working with.  So I although I
> > appreciate
> > > > the
> > > > > > > > > > advice
>
> ...
>
> 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 fluent-nhibern...@googlegroups.com.
To unsubscribe from this group, send email to 
fluent-nhibernate+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/fluent-nhibernate?hl=en.

Reply via email to