NHibernate:在为插入操作调用flush时接收索引超出范围

4 nhibernate insert flush

在使用NHibernate时,我花了大部分时间尝试解决此消息:"索引超出范围.必须是非负数且小于集合的大小.参数名称:index"

我的更新和删除工作正常,但调用save()后调用flush不起作用.我不认为发布所有代码(有很多)是有用的,因为我不确定你现在需要看到什么.我正在尝试保存的数据访问对象使用复合键,如果这有帮助的话.另外,我正在使用NHibernate.Mapping.Attributes来创建我的映射.

似乎在我的堆栈跟踪中,NHibernate正在尝试向ADO.Net类发送无效数量的参数以进行插入操作.话虽这么说,我有跟踪设置为true以查看sql语句,但错误是在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         
}
Run Code Online (Sandbox Code Playgroud)

在NHibernate.Type.DecimalType.Set的IBM.Data.DB2.iSeries.iDB2ParameterCollection.System.Collections.IList.get_Item(Int32索引)的System.Collections.ArrayList.get_Item(Int32索引)中(IDbCommand st,Object value,Int32 NHibernate.Type.CompullType.NullSafeSet上的NHibernate.Type.NullableType.NullSafeSet(IDbCommand st,Object value,Int32 index,ISessionImplementor session)中的NHibernate.Type.NullableType.NullSafeSet(IDbCommand cmd,Object value,Int32 index) 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语句,ISessionImplementor会话,Int32索引)NHibernate.Persister.Entity的NHibernate.Persister.Entity.AbstractEntityPersister.Insert(Object id,Object [] fields,Boolean [] notNull,Int32 j,SqlCommandInfo sql,Object obj,ISessionImplementor session) .Abstrac tEntityPersister.Insert(对象ID,对象[]字段,对象OBJ,ISessionImplementor会话)在NHibernate.Action.EntityInsertAction.Execute()在NHibernate.Engine.ActionQueue.Execute(IExecutable可执行)在NHibernate.Engine.ActionQueue.ExecuteActions(IList的列表)NHibernate.Ection.Event.Default.DefaultFlushEventListener.OnFlush(FlushEvent事件)NHibernate.Ivent.SessionImpl.Flush()的NHibernate.Event.Default.AbstractFlushingEventListener.PerformExecutions(IEventSource会话)的NHibernate.Engine.ActionQueue.ExecuteActions()在WTS.Data.DB2.CGC.ProddataRepository.Insert(ProddataDAO Entity)的C:\ Documents and Settings\briant\My Documents\Visual Studio 2008\Projects\WTSCGCDAL\WTSCGCDAL\ProddataRepository.cs:WTS.WTSCGCAppInterface第73行. C:\ Documents and Settings\briant\My Documents\Visual Studio 2008\Projects\WTSCGCAppInterface\WTSCGCAppInterface\ProductionDataUserControlBase.cs中的ProductionDataUserControlBase.TestInsert():WTSCGCAppInterface.Window1.Button_Click_1中的第483行(O bject sender,RoutedEventArgs e)在C:\ Documents and Settings\briant\My Documents\Visual Studio 2008\Projects\WTSCGCAppInterface\WTSCGCAppInterface\Window1.xaml.cs:第48行,位于System.Windows.RoutedEventHandlerInfo.InvokeHandler(对象目标,RoutedEventArgs) routedEventArgs)在System.Windows.EventRoute.InvokeHandlersImpl(对象源,RoutedEventArgs指定参数时,布尔再加注)在System.Windows.UIElement.RaiseEventImpl(DependencyObject的发件人,RoutedEventArgs参数)在System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)上系统. Windows.Controls.Primitives.ButtonBase.OnClick()在System.Windows.Controls.Button.OnClick()在System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)上System.Windows.UIElement.OnMouseLeftButtonUpThunk(对象发件人,MouseButtonEventArgs e)在System.Windows.RoutedEventArgs.InvokeHandler(委托处理程序,对象ta)的System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler,Object genericTarget)中 rget)在System.Windows.EindRoute.InvokeHandlersImpl(Object source,RoutedEventArgs args,Boolean reRaised)的System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target,RoutedEventArgs routedEventArgs)处于System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender,RoutedEventArgs args, RoutedEvent newEvent)位于System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler,Object genericTarget)的System.Windows.UIElement.OnMouseUpThunk(Object sender,MouseButtonEventArgs e)的System.Windows.UIElement.CrackMouseButtonEventAndReRaiseEvent(DependencyObject sender,MouseButtonEventArgs e)中在System.Windows.RoutedEventArgs.InvokeHandler(委托处理程序,对象目标)在System.Windows.RoutedEventHandlerInfo.InvokeHandler(对象目标,RoutedEventArgs routedEventArgs)在System.Windows.EventRoute.InvokeHandlersImpl(对象源,RoutedEventArgs指定参数时,布尔再加注)在系统.Windows.UIElement.RaiseEventImpl(DependencyObject sender,RoutedEventArg 在System.Windows.Input上的System.Windows.InputManager.ProcessInput(InputEventArgs输入)处的System.Windows.InputManager.ProcessStagingArea()处的System.Windows.UIElement.RaiseEvent(RoutedEventArgs args,布尔值为受信任)处的s args) System.Windows.Interop.HwndMouseInputProvider.FilterMessage的System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd,InputMode mode,Int32 timestamp,RawMouseActions actions,Int32 x,Int32 y,Int32 wheel)中的.InputProviderSite.ReportInput(InputReport inputReport)在MS.Win32.HwndWrapper.WndProc的System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd,Int32 msg,IntPtr wParam,IntPtr lParam,Boolean&handling)中的(IntPtr hwnd,Int32 msg,IntPtr wParam,IntPtr lParam,Boolean&handling)在MS.Win32.HwndSubclass.DispatcherCallbackOperation(对象O)在System.Windows.Threading.ExceptionWrapper.InternalRealCall(代表回调(IntPtr的HWND,MSG的Int32,IntPtr的wParam中,IntPtr的lParam的,布尔逻辑处理),对象指定参数时,布尔isSinglePa rameter)在System.Windows.Threading.ExceptionWrapper.TryCatchWhen(对象源,代表回调,对象指定参数时,布尔isSingleParameter,代表catchHandler)在System.Windows.Threading.Dispatcher.WrappedInvoke(代表回调,对象指定参数时,布尔isSingleParameter,代表catchHandler )在MS的System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority,Delegate方法,Object arg)中的System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority,TimeSpan timeout,Delegate方法,Object args,Boolean isSingleParameter). System.Windows.Threading上System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame框架)的MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG&msg)中的Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd,Int32 msg,IntPtr wParam,IntPtr lParam) .Dispatcher.PushFrame(DispatcherFrame框架)
在System.Windows.Threading.Dispatcher.Run()处于System.Windows.Application.RunDispatcher(Object ignore)的System.Windows.Application.RunInternal(窗口窗口),位于系统的System.Windows.Application.Run(窗口窗口) .Windows.Application.Run()位于C:\ Documents and Settings\briant\My Documents\Visual Studio 2008\Projects\WTSCGCAppInterface\WTSCGCAppInterface\obj\Debug\App.g.cs中的WTSCGCAppInterface.App.Main():line
System.Threading 上的Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()中的System.AppDomain.ExecuteAssembly(String assemblyFile,Evidence assemblySecurity,String [] args)上的System.AppDomain._nExecuteAssembly(Assembly assembly,String [] args)处的0
System.Threading.ThreadHelper.ThreadStart()的System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback回调,对象状态)中的.ThreadHelper.ThreadStart_Context(Object state )

tol*_*sm7 6

当表中缺少列时,通常会出现此错误.因此,如果某个类具有映射到数据库中缺少的表列的属性,那么您将看到此错误.

基本上检查映射和数据库表之间是否存在不匹配(缺少列,类型不匹配等).问题可能出在相关的表/实体上,而不是您要保存的那个.