-
Notifications
You must be signed in to change notification settings - Fork 936
Description
When updating to NHibernate 5.3.0 or later (tested on 5.3.0 and 5.3.5) from 5.2.7, I started to get IndexOutOfRangeExceptions when deleting entities that had One-To-One mapping enabled.
The exception below is from a minimum reproduction case linked to below.
System.IndexOutOfRangeException: Index was outside the bounds of the array.
at NHibernate.Persister.Entity.AbstractEntityPersister.GenerateSQLDeleteStrings(Object[] loadedState)
at NHibernate.Persister.Entity.AbstractEntityPersister.Delete(Object id, Object version, Object obj, ISessionImplementor session)
at NHibernate.Action.EntityDeleteAction.Execute()
at NHibernate.Engine.ActionQueue.InnerExecute(IExecutable executable)
at NHibernate.Engine.ActionQueue.ExecuteActions[T](List`1 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 NHibernate.Impl.SessionImpl.FlushBeforeTransactionCompletion()
at NHibernate.Impl.SessionImpl.BeforeTransactionCompletion(ITransaction tx)
at NHibernate.Transaction.AdoTransaction.Commit()
at OutOfBounds.TestScenario.DeleteAll() in /home/matt/Work/nh-out-of-bounds/OutOfBounds/TestScenario.cs:line 75
at OutOfBounds.TestScenario.Test() in /home/matt/Work/nh-out-of-bounds/OutOfBounds/TestScenario.cs:line 28
at OutOfBounds.Program.Main(String[] args) in /home/matt/Work/nh-out-of-bounds/OutOfBounds/Program.cs:line 33
From trying to figure it out myself, it seems specific to building the where clause for a dynamic update. It looks like in 5.2.7, the GenerateSQLDeleteStrings method in AbstractEntityPersister was depending on the OneToOneType returning an empty array for ToColumnNullness to kick it out of the query, but in 5.3.0 w/ ticket 2084, that got improved to return appropriate values.
Reproduction Case: https://github.com/mdshaner/nh-out-of-bounds
A note about the reproduction case is that it is expecting a MSSQL database with the tables already created, the repo should include a sql script to create the tables at least. It will also need the connection string provided to the database.