-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 
Author Message
 Post subject: Invalid index nn for this SqlParameterCollection with Count=
PostPosted: Thu Jun 19, 2008 6:39 pm 
Newbie

Joined: Fri Jun 06, 2008 6:25 pm
Posts: 8
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Build 2.0.0.Alpha1:

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
  <class name="Framework.Model.JobDao, Framework" table="Job" lazy="false">
    <id name="id" column="job_pkey" unsaved-value="0">
      <generator class="identity"/>
    </id>

    <property name="JobType" column="jobtype" not-null="true"/>
    <property name="JobId" column="jobid" not-null="true"/>
    <property name="JobStatPKey" column="jobstat_pkey" not-null="true"/>
    <property name="InvStatPKey" column="invstat_pkey" not-null="true"/>
    <property name="BtPKey" column="bt_pkey" not-null="true"/>
    <property name="CoPKey" column="co_pkey" not-null="true"/>
    <property name="BookedBy" column="bookedby" not-null="true"/>
    <property name="DispatchedBy" column="dispatchedby" not-null="false"/>
    <property name="LastDrPKey" column="lastdr_pkey" not-null="false"/>
    <property name="FpPKey" column="fp_pkey" not-null="true"/>
    <property name="SvPKey" column="sv_pkey" not-null="true"/>
    <property name="JobColor" column="jobcolor" not-null="true"/>
    <property name="PrevJobPKey" column="prevjob_pkey" not-null="false"/>
    <property name="NextJobPKey" column="nextjob_pkey" not-null="false"/>
    <property name="MstrJobPKey" column="mstrjob_pkey" not-null="false"/>
    <property name="RateGrpPKey" column="rategp_pkey" not-null="false"/>
    <property name="CostGrpPKey" column="costcgrp_pkey" not-null="false"/>
    <property name="RateLocked" column="ratelocked" not-null="true"/>
    <property name="CostLocked" column="costlocked" not-null="true"/>
    <property name="HasException" column="HasException" not-null="true"/>
    <property name="ReqVtPKey" column="reqvt_pkey" not-null="false"/>
    <property name="PtPKey" column="pt_pkey" not-null="true"/>
   
    <property name="LastModBy" column="LastModBy" not-null="false"/>
    <property name="LastModAt" column="LastModAt" type="DateTime" not-null="true"/>

    <!-- One-to-many mapping: JobDetails (read & write)-->
    <bag name="JobDetails" cascade="all" inverse="true" lazy="false" >
      <key column="job_pkey" />
      <one-to-many class="Framework.Model.JobDetail, Framework" />
    </bag>
   
  </class>
</hibernate-mapping>



<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
  <class name="Framework.Model.JobDetail, Framework" table="JobDetail" lazy="false">
    <id name="PKey" column="JobD_PKey" unsaved-value="0">
      <generator class="identity"/>
    </id>
    <property name="JobPKey" column="job_pkey" not-null="true"/>
    <property name="InfoPKey" column="info_pkey" not-null="true"/>
    <property name="NumValue" column="numval" not-null="false"/>
    <property name="CharValue" column="charval" not-null="false"/>
    <property name="BitValue" column="bitval" not-null="false"/>
    <property name="TextValue" column="textval" not-null="false"/>
    <property name="UmPKey" column="um_pkey" not-null="true"/>

    <property name="LastModBy" column="LastModBy" not-null="false"/>
    <property name="LastModAt" column="LastModAt" type="DateTime" not-null="true"/>

    <!-- Many-to-one mapping: JobDao -->
    <many-to-one name="Parent" class="Framework.Model.JobDao, Framework" column="job_pkey" not-null="true" />

  </class>
</hibernate-mapping>


My calling code is as follows:
Code:
public void Save( JobDao entity )
{
   m_pm.SaveEntityInTransaction(cloneDao);
}

internal void SaveEntityInTransaction(IEntity entity)
{
   PersistanceManager pm = Instance;
   ISession session = null;
   try
   {
      // Begin Transaction
      session = pm.GetCurrentSession();
      ITransaction tx = session.BeginTransaction();
         session.SaveOrUpdate(entity);
      tx.Commit();
   }
   finally
   {
      if ( pm != null )
         pm.CloseSession();
   }
}



Call Stack

NHibernate.DLL!NHibernate.Type.Int32Type.Set(System.Data.IDbCommand rs = {System.Data.SqlClient.SqlCommand}, object value = 204, int index = 10) Line 60 + 0x15 bytes C#

NHibernate.DLL!NHibernate.Type.NullableType.NullSafeSet(System.Data.IDbCommand cmd = {System.Data.SqlClient.SqlCommand}, object value = 204, int index = 10) Line 180 + 0x13 bytes C#

NHibernate.DLL!NHibernate.Type.NullableType.NullSafeSet(System.Data.IDbCommand st = {System.Data.SqlClient.SqlCommand}, object value = 204, int index = 10, NHibernate.Engine.ISessionImplementor session = {NHibernate.Impl.SessionImpl}) Line 139 + 0xf bytes C#

NHibernate.DLL!NHibernate.Persister.Entity.AbstractEntityPersister.Dehydrate(object id = 204, object[] fields = {object[10]}, object rowId = null, bool[] includeProperty = {bool[10]}, bool[][] includeColumns = {bool[10][]}, int table = 0, System.Data.IDbCommand statement = {System.Data.SqlClient.SqlCommand}, NHibernate.Engine.ISessionImplementor session = {NHibernate.Impl.SessionImpl}, int index = 10) Line 2361 + 0x22 bytes C#

NHibernate.DLL!NHibernate.Persister.Entity.AbstractEntityPersister.Update(object id = 204, object[] fields = {object[10]}, object[] oldFields = null, object rowId = null, bool[] includeProperty = {bool[10]}, int j = 0, object oldVersion = null, object obj = {Framework.Model.JobDetail}, NHibernate.SqlCommand.SqlCommandInfo sql = {NHibernate.SqlCommand.SqlCommandInfo}, NHibernate.Engine.ISessionImplementor session = {NHibernate.Impl.SessionImpl}) Line 2668 + 0x26 bytes C#

NHibernate.DLL!NHibernate.Persister.Entity.AbstractEntityPersister.UpdateOrInsert(object id = 204, object[] fields = {object[10]}, object[] oldFields = null, object rowId = null, bool[] includeProperty = {bool[10]}, int j = 0, object oldVersion = null, object obj = {Framework.Model.JobDetail}, NHibernate.SqlCommand.SqlCommandInfo sql = {NHibernate.SqlCommand.SqlCommandInfo}, NHibernate.Engine.ISessionImplementor session = {NHibernate.Impl.SessionImpl}) Line 2627 + 0x23 bytes C#

NHibernate.DLL!NHibernate.Persister.Entity.AbstractEntityPersister.Update(object id = 204, object[] fields = {object[10]}, int[] dirtyFields = null, bool hasDirtyCollection = false, object[] oldFields = null, object oldVersion = null, object obj = {Framework.Model.JobDetail}, object rowId = null, NHibernate.Engine.ISessionImplementor session = {NHibernate.Impl.SessionImpl}) Line 2885 + 0x10c bytes C#

NHibernate.DLL!NHibernate.Action.EntityUpdateAction.Execute() Line 70 + 0x24 bytes C#

NHibernate.DLL!NHibernate.Engine.ActionQueue.Execute(NHibernate.Action.IExecutable executable = {EntityUpdateAction[Framework.Model.JobDetail#204]}) Line 130 + 0x8 bytes C#

NHibernate.DLL!NHibernate.Engine.ActionQueue.ExecuteActions(System.Collections.IList list = Count = 3) Line 113 + 0xb bytes C#

NHibernate.DLL!NHibernate.Engine.ActionQueue.ExecuteActions() Line 147 + 0xa bytes C#

NHibernate.DLL!NHibernate.Event.Default.AbstractFlushingEventListener.PerformExecutions(NHibernate.Event.IEventSource session = {NHibernate.Impl.SessionImpl}) Line 240 + 0x14 bytes C#

NHibernate.DLL!NHibernate.Event.Default.DefaultFlushEventListener.OnFlush(NHibernate.Event.FlushEvent event = {NHibernate.Event.FlushEvent}) Line 19 + 0x9 bytes C#

NHibernate.DLL!NHibernate.Impl.SessionImpl.Flush() Line 1186 + 0x33 bytes C#

NHibernate.DLL!NHibernate.Transaction.AdoTransaction.Commit() Line 163 + 0xc bytes C#

Framework.DLL!Framework.Persistance.PersistanceManager.SaveEntityInTransaction(Framework.Model.Core.IEntity entity = {Framework.Model.JobDao}) Line 109 + 0x9 bytes C#

Framework.DLL!Framework.Persistance.PersistanceManagerJob.Save(Framework.Model.JobDao entity = {Framework.Model.Job}) Line 27 + 0xc bytes C#


SQL Server 2005


This is the SQL that is about to be executed after the parameter values are set (that is what is currently being done).
"UPDATE JobDetail SET info_pkey = @p0, numval = @p1, charval = @p2, bitval = @p3, textval = @p4, um_pkey = @p5, LastModBy = @p6, LastModAt = @p7, job_pkey = @p8 WHERE JobD_PKey = @p9"



This is the error I received:
Invalid index 10 for this SqlParameterCollection with Count=10.

This is the code that is being executed in nHibernate file: Int32.cs line 58
Code:
public override void Set(IDbCommand rs, object value, int index)
{
   ((IDataParameter)rs.Parameters[index]).Value = value;
}


I inspected the 'value' and it appears that it should be for parameter 0. The 'index' who's value is 10, is clearly incorrect because there are only 10 parameters (0 - 9).

The problem appears to be in the file nHibernate file AbstractEntityPersister (line 2332) in the method called "protected int Dehydrate(object id, object[] fields, object rowId, bool[] includeProperty, bool[][] includeColumns, int table, IDbCommand statement, ISessionImplementor session, int index)"

In this method, 'index' was modified/updated from 0 to the invalid value of 10.

Please help!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 20, 2008 3:09 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
You've mapped the column "job_pkey" twice:

Code:
<property name="JobPKey" column="job_pkey" not-null="true"/>

<many-to-one name="Parent" class="Framework.Model.JobDao, Framework" column="job_pkey" not-null="true" />


I'm not sure if this allowed at all, but at least you should add insert="false" and update="false" on the property:
Code:
<property name="JobPKey" column="job_pkey" not-null="true" insert=false" update="false"/>


If that doesn't help, try it with a formula on that property.

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 09, 2008 5:56 am 
Beginner
Beginner

Joined: Tue Sep 09, 2008 5:42 am
Posts: 22
Location: Romania
Worked for me ... Thanks Wolli you made my day!


Top
 Profile  
 
 Post subject: Re: Invalid index nn for this SqlParameterCollection with Count=
PostPosted: Fri May 29, 2009 1:54 pm 
Newbie

Joined: Mon May 18, 2009 12:00 pm
Posts: 2
Thanks dude .. saved me a day !!!!!


Top
 Profile  
 
 Post subject: Re: Invalid index nn for this SqlParameterCollection with Count=
PostPosted: Thu Jul 16, 2009 11:50 am 
Newbie

Joined: Thu Jul 16, 2009 11:49 am
Posts: 1
Thanks from me too!


Top
 Profile  
 
 Post subject: Re: Invalid index nn for this SqlParameterCollection with Count=
PostPosted: Thu Dec 17, 2009 10:44 am 
Newbie

Joined: Thu Dec 17, 2009 10:42 am
Posts: 1
Hi, I am also facing the same problem. but for me i am using composite id and one of the columns in the composite column is used in the relation ship many to one. so i am not sure how can i set it as insert = false and update = false. could you please help me on this?

thanks ina dvance


Top
 Profile  
 
 Post subject: Re: Invalid index nn for this SqlParameterCollection with Count=
PostPosted: Mon Jul 26, 2010 12:10 pm 
Beginner
Beginner

Joined: Tue Sep 09, 2008 5:42 am
Posts: 22
Location: Romania
just set update=false and insert=false on your many-to-one relation in the mapping


Top
 Profile  
 
 Post subject: Re: Invalid index nn for this SqlParameterCollection with Count=
PostPosted: Fri Nov 19, 2010 4:45 am 
Newbie

Joined: Fri Nov 19, 2010 4:35 am
Posts: 1
Here too. There was simply a duplicate column reference in the mapping.

Thanks for the pointer!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.