开发者

NHibernate: receiving index out of range while calling flush for insert operation

开发者 https://www.devze.com 2022-12-13 20:26 出处:网络
I\'ve spent the better part of my day trying to solve this message while using NHibernate: \"Index was out of range. Must be non-negative and less than the size of the collection.

I've spent the better part of my day trying to solve this message while using NHibernate: "Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index"

My update and delete work just fine but the call to flush after a call to save() does not work. I don't think it will be useful to post all of the code (there's a lot) because I'm not sure what you'll need to see at this point. My data access object I'm trying to save uses a composite key if that helps. Also, I'm using NHibernate.Mapping.Attributes to create my mapping.

It appears that in my stack trace NHibernate is attempting to send an invalid number of parameters to the ADO.Net class for the insert operation. That being said, I have trace set to true in order to view sql statements but the error is raised prior to the sql statement being sent to the output so I'm not sure what it's attempting to build..

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         
}

at 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 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 WTS.Data.DB2.CGC.ProddataRepository.Insert(ProddataDAO Entity) in 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) at System.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) 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.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.InputProviderSite.ReportInput(InputReport inputReport) at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel) 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.HwndWrapper.WndProc(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) at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler) at System.Windows.Threading.Dispatcher.WrappedInvoke(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) at MS.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) at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)

at System.Windows.Threading.Dispatcher.Run() at System.Windows.Application.RunDispatcher(Object ignore) 开发者_如何学Pythonat System.Windows.Application.RunInternal(Window window) at System.Windows.Application.Run(Window window) at System.Windows.Application.Run() at WTSCGCAppInterface.App.Main() in C:\Documents and Settings\briant\My Documents\Visual Studio 2008\Projects\WTSCGCAppInterface\WTSCGCAppInterface\obj\Debug\App.g.cs:line 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(Object state)

at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart()


This error usually appears when there are columns missing from your tables. So if a class has a property mapped to table column that is missing from the database then you will see this error.

Basically check for mismatches between your mappings and your database tables (missing columns, type mismatches etc). The problem may be on a related table/entity and not on the one you are trying to save.


I had also this problem and after hours of googling, I found out that was a problem in the mapping: I had a column with the same name twice (in my case it was both a <key-property> , as part of a <composite-id>, and also a column in the <many-to-one> element. I solved changing <key-property> to <key-many-to-one> and deleting the <many-to-one> element).

0

精彩评论

暂无评论...
验证码 换一张
取 消