4

NHibernateを使用しているときに、このメッセージを解決するために1日の大半を費やしました:「インデックスは範囲外でした。負ではなく、コレクションのサイズ未満である必要があります。パラメーター名:インデックス」

私の更新と削除は問題なく機能しますが、save()の呼び出し後にフラッシュする呼び出しは機能しません。この時点で何を表示する必要があるかわからないため、すべてのコード(たくさんあります)を投稿することは役に立たないと思います。保存しようとしているデータアクセスオブジェクトは、それが役立つ場合は複合キーを使用します。また、NHibernate.Mapping.Attributesを使用してマッピングを作成しています。

スタックトレースで、NHibernateが挿入操作のために無効な数のパラメーターをADO.Netクラスに送信しようとしているようです。そうは言っても、SQLステートメントを表示するためにトレースをtrueに設定しましたが、SQLステートメントが出力に送信される前にエラーが発生するため、何をビルドしようとしているのかわかりません。

public void Insert(ProddataDAO Entity)
{
        Entity.PSEQ = GetNewSeqID(Entity.PCUST); // <- because I'm using a composite key, this function gets my a unique value by a group
        NHibernateHelperCGC.CurrentSession.Save(Entity);            
        NHibernateHelperCGC.CurrentSession.Flush();   // <-This raises the error         
}

System.Collections.ArrayList.get_Item(Int32 index)at IBM.Data.DB2.iSeries.iDB2ParameterCollection.System.Collections.IList.get_Item(Int32 index)at NHibernate.Type.DecimalType.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 NHibernate.Persisterでのステートメント、ISessionImplementorセッション、Int32インデックス)。NHibernate.Persister.Entity.AbstractEntityPersister.Insert(Object id、Object [] fields、 Object obj、ISessionImplementor session)at NHibernate.Action.EntityInsertAction.Execute()at NHibernate.Engine.ActionQueue.Execute(IExecutable execute)at NHibernate.Engine.ActionQueue.ExecuteActions(IList list)at NHibernate.Engine.ActionQueue.ExecuteActions() NHibernate.Event.Default.AbstractFlushingEventListener.PerformExecutions(IEventSource session)at NHibernate.Event.Default.DefaultFlushEventListener.OnFlush(FlushEvent event)at NHibernate.Impl.SessionImpl.Flush()at WTS.Data.DB2.CGC.ProddataRepository.Insert (ProddataDAOエンティティ)C:\ Documents and Settings \ briant \ My Documents \ Visual Studio 2008 \ Projects \ WTSCGCDAL \ WTSCGCDAL \ ProddataRepository.cs:line 73 at WTS.WTSCGCAppInterface.ProductionDataUserControlBase.TestInsert()in C:\ Documents and Settings \ briant \ My Documents \ Visual Studio 2008 \ Projects \ WTSCGCAppInterface \ WTSCGCAppInterface \ ProductionDataUserControlBase.cs:line 483 at WTSCGCAppInterface.Window1.Button_Click_1(Object sender、RoutedEventArgs e)in C:\ Documents and Settings \ briant \ My Documents \ Visual Studio 2008 \ Projects \ WTSCGCAppInterface \ WTSCGCAppInterface \ Window1.xaml.cs:line 48 at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target、RoutedEventArgs routedEventArgs)at System.Windows.EventRoute.InvokeHandlersImpl(Object source、RoutedEventArgs args、Boolean reRaised)atSystem.Windows.UIElement。RaiseEventImpl(DependencyObject sender、RoutedEventArgs args)at System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)at System.Windows.Controls.Primitives.ButtonBase.OnClick()at System.Windows.Controls.Button.OnClick()at System.Windows .Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)at System.Windows.UIElement.OnMouseLeftButtonUpThunk(Object sender、MouseButtonEventArgs e)at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler、Object genericTarget)atSystem.Windows.RoutedEventArgs .InvokeHandler(Delegate handler、Object target)at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target、RoutedEventArgs routedEventArgs)at System.Windows.EventRoute.InvokeHandlersImpl(Object source、RoutedEventArgs args、System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender、RoutedEventArgs args、RoutedEvent newEvent)at System.Windows.UIElement.CrackMouseButtonEventAndReRaiseEvent(DependencyObject sender、MouseButtonEventArgs e)at System.Windows.UIElement.OnMouseUpThunk(Object sender、MouseButtonEventArgs e )at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler、Object genericTarget)at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler、Object target)at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target、RoutedEventArgs routedEventArgs)at System .Windows.EventRoute.InvokeHandlersImpl(Object source、RoutedEventArgs args、Boolean reRaised)at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender、RoutedEventArgs args)at System.Windows.UIElement.RaiseEvent(RoutedEventArgs args、Boolean Trusted)at System.Windows.Input.InputManager.ProcessStagingArea()at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)at System.Windows.Input System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd、InputModeモード、Int32タイムスタンプ、RawMouseActionsアクション、Int32 x、Int32 y、Int32ホイール)の.InputProviderSite.ReportInput(InputReport inputReport)at System.Windows.Interop.HwndMouseInputProvider.FilterMessage (IntPtr hwnd、Int32 msg、IntPtr wParam、IntPtr lParam、Boolean&handled)at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd、Int32 msg、IntPtr wParam、IntPtr lParam、Boolean&handled)at MS.Win32.HwndProc. (IntPtr hwnd、Int32 msg、IntPtr wParam、IntPtr lParam、Boolean&handled)at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback、Object args、Boolean isSingleParameter)atSystem.Windows.Threading.ExceptionWrapper。 System.Windows.Threading.Dispatcher.WrappedInvoke(コールバックのデリゲート、オブジェクトargs、ブールisSingleParameter、catchHandlerのデリゲート)のTryCatchWhen(Object source、Delegate callback、Object args、Boolean isSingleParameter、Delegate catchHandler)at System.Windows.Threading.Dispatcher.InvokeImpl (DispatcherPriority priority、TimeSpan timeout、Delegate method、Object args、Boolean isSingleParameter)at System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority、Delegate method、Object arg)atMS.Win32。HwndSubclass.SubclassWndProc(IntPtr hwnd、Int32 msg、IntPtr wParam、IntPtr lParam)at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG&msg)at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)atSystem.Windows.Threading.Dis。 .PushFrame(DispatcherFrameフレーム)
System.Windows.Threading.Dispatcher.Run()at System.Windows.Application.RunDispatcher(Object ignore)at System.Windows.Application.RunInternal(Window window)at System.Windows.Application.Run(Window window)at System C:\ Documents and Settings \ briant \ My Documents \ Visual Studio 2008 \ Projects \ WTSCGCAppInterface \ WTSCGCAppInterface \ obj \ Debug \ App.g.cs:lineのWTSCGCAppInterface.App.Main()にある.Windows.Application.Run() 0 at System.AppDomain._nExecuteAssembly(Assembly assembly、String [] args)at System.AppDomain.ExecuteAssembly(String assemblyFile、Evidence assemblySecurity、String [] args)at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading .ThreadHelper.ThreadStart_Context(オブジェクトの状態)
System.Threading.ExecutionContext.Run(ExecutionContextexecutionContext、ContextCallbackコールバック、オブジェクト状態)でSystem.Threading.ThreadHelper.ThreadStart()で

4

2 に答える 2

6

このエラーは通常、テーブルに欠落している列がある場合に表示されます。そのため、データベースにないテーブル列にマップされたプロパティがクラスにある場合、このエラーが表示されます。

基本的に、マッピングとデータベース テーブル間の不一致 (列の欠落、型の不一致など) を確認します。問題は、保存しようとしているものではなく、関連するテーブル/エンティティにある可能性があります。

于 2009-12-10T12:00:01.537 に答える
1

私もこの問題を抱えていて、何時間もグーグルで調べた後、それがマッピングの問題であることがわかりました:同じ列がname2回ありました(私の場合、それは両方であり<key-property>、 a の一部であり<composite-id>、の列でもありました要素への変更と削除<many-to-one>を解決し<key-property>ました)。<key-many-to-one><many-to-one>

于 2015-06-16T12:15:43.513 に答える