In one of the two property put insert=false update=false or, even better,
don't map the many-to-one if you are not using it and change the
ParentPersonId accessor to one of "nosetter" accessors
2008/10/27 Tigraine <[EMAIL PROTECTED]>

>
> Hi,
>
> I have a Entity called Person that should have a Parent property. The
> Parent property is a FK reference to the parent Person and can be
> null.
> Now, I decided that performance wise it's easier to simply get all
> Persons in a flat list, and create the tree in memory.
>
> To accomplish this (my ParentPerson property is lazy loaded) I tried
> to introduce a new Field to the Domain Object called ParentPersonId
> that maps so the same column as the many-to-one relationship.
>
> After I ran my Unit Tests everything failed with the following stack
> trace:
>
> System.IndexOutOfRangeException: Ungültiger Index 33 für
> SqlParameterCollection mit Count=33.
> bei System.Data.SqlClient.SqlParameterCollection.RangeCheck(Int32
> index)
> bei System.Data.SqlClient.SqlParameterCollection.GetParameter(Int32
> index)
> bei
>
> System.Data.Common.DbParameterCollection.System.Collections.IList.get_Item(Int32
> index)
> bei NHibernate.Type.Int64Type.Set(IDbCommand rs, Object value, Int32
> index)
> bei NHibernate.Type.NullableType.NullSafeSet(IDbCommand cmd, Object
> value, Int32 index)
> bei NHibernate.Type.NullableType.NullSafeSet(IDbCommand st, Object
> value, Int32 index, ISessionImplementor session)
> bei
> NHibernate.Persister.Entity.AbstractEntityPersister.Dehydrate(Object
> id, Object[] fields, Object rowId, Boolean[] includeProperty, Boolean[]
> [] includeColumns, Int32 table, IDbCommand statement,
> ISessionImplementor session, Int32 index)
> bei NHibernate.Persister.Entity.AbstractEntityPersister.Insert(Object
> id, Object[] fields, Boolean[] notNull, Int32 j, SqlCommandInfo sql,
> Object obj, ISessionImplementor session)
> bei NHibernate.Persister.Entity.AbstractEntityPersister.Insert(Object
> id, Object[] fields, Object obj, ISessionImplementor session)
> bei NHibernate.Action.EntityInsertAction.Execute()
> bei NHibernate.Engine.ActionQueue.Execute(IExecutable executable)
> bei NHibernate.Engine.ActionQueue.ExecuteActions(IList list)
> bei NHibernate.Engine.ActionQueue.ExecuteActions()
> bei
>
> NHibernate.Event.Default.AbstractFlushingEventListener.PerformExecutions(IEventSource
> session)
> bei
> NHibernate.Event.Default.DefaultFlushEventListener.OnFlush(FlushEvent
> event)
> bei NHibernate.Impl.SessionImpl.Flush()
> bei NHibernate.Transaction.AdoTransaction.Commit()
> bei
>
> mlmManager.Repositories.NHibernate.Tests.PersonRepository_Fixture.CreateInitialData()
> in PersonRepository_Fixture.cs: line 122.
> bei
>
> mlmManager.Repositories.NHibernate.Tests.PersonRepository_Fixture.SetupContext()
> in PersonRepository_Fixture.cs: line 22.
>
> Sorry it's in german, "bei" means at and the top line says "Invalid
> Index 33 for SqlParameterCollection with Count=33"
>
> The mapping file looks like this:
>
> <class name="Person">
>    <id name="Id" type="Int64">
>      <generator class="hilo" />
>    </id>
>    <property name="ParentPersonId" column="ParentId" type="Int64" />
>    <many-to-one name="Parent" class="Person" column="ParentId" />
>
>    <set name="Children" cascade="all-delete-orphan">
>      <key column="ParentId" foreign-key="fk_Person_ParentPerson" />
>      <one-to-many class="Person"/>
>    </set>
> </class>
>
> (I omitted the irrelevant value fields).
>
> Maybe you have an Idea why I am getting this error? I can't really
> figure it out..
>
> greetings
>
> Daniel Hoelbling
> http://www.tigraine.at
> >
>


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

Reply via email to