One-To-Many of Union-Subclass saves to wrong table
Description
Environment
Attachments
Activity
Unfortunatelly the "marked set with inverse" is a good workaround and it solves my problem. Thanks!
I think it is a question of a viewpoint. I have several types of union-subclass relations. All types working fine, except this situation. NHibernate forgets to check inherited entities of the "Measure" entity type, so it failed to make the association between the owner of the set and the "set entity". This issue exists in a One-To-Many with Many-To-One entity relation scenario.
I think the title of this issue might not be accurate enough. union-subclass
looks like the most important part of your issue - the problem boils down to the `Measures` table being updated instead of the `Currencies` table. union-subclass
is the part of your mapping that specifies which table these two entities should go in. I think "One-To-Many of Union-Subclass saves to wrong table" would be a better title.
Also, MeasureGroup.measures
should be marked inverse
.
The exception:
2013-09-05 13:47:33,786 DEBUG [Agent: adapter run thread for test 'TestDemoBug' with id 'a769cf8d-dc3d-408c-b384-51c510aaf050'] [NHibernate.SQL] - Batch commands:
command 0:UPDATE Measures SET measureGroup_systemId = @p0, measureGroup_deviceId = @p1, measureGroup_id = @p2 WHERE systemId = @p3 AND deviceId = @p4 AND id = @p5;@p0 = 1 [Type: Int64 (0)], @p1 = 1 [Type: Int64 (0)], @p2 = 781670897921 [Type: Int64 (0)], @p3 = 1 [Type: Int64 (0)], @p4 = 2 [Type: Int64 (0)], @p5 = 781671005783 [Type: Int64 (0)]
command 1:UPDATE Measures SET measureGroup_systemId = @p0, measureGroup_deviceId = @p1, measureGroup_id = @p2 WHERE systemId = @p3 AND deviceId = @p4 AND id = @p5;@p0 = 1 [Type: Int64 (0)], @p1 = 1 [Type: Int64 (0)], @p2 = 781670897921 [Type: Int64 (0)], @p3 = 1 [Type: Int64 (0)], @p4 = 3 [Type: Int64 (0)], @p5 = 781671019530 [Type: Int64 (0)]
2013-09-05 13:47:33,816 DEBUG [Agent: adapter run thread for test 'TestDemoBug' with id 'a769cf8d-dc3d-408c-b384-51c510aaf050'] [NHibernate.AdoNet.AbstractBatcher] - Closed IDbCommand, open IDbCommands: 0
2013-09-05 13:47:33,816 ERROR [Agent: adapter run thread for test 'TestDemoBug' with id 'a769cf8d-dc3d-408c-b384-51c510aaf050'] [NHibernate.Event.Default.AbstractFlushingEventListener] - Could not synchronize database state with session
NHibernate.StaleStateException: Batch update returned unexpected row count from update; actual row count: 0; expected: 2
at NHibernate.AdoNet.Expectations.VerifyOutcomeBatched(Int32 expectedRowCount, Int32 rowCount)
at NHibernate.AdoNet.SqlClientBatchingBatcher.DoExecuteBatch(IDbCommand ps)
at NHibernate.AdoNet.AbstractBatcher.ExecuteBatchWithTiming(IDbCommand ps)
at NHibernate.AdoNet.AbstractBatcher.ExecuteBatch()
at NHibernate.Engine.ActionQueue.ExecuteActions(IList list)
at NHibernate.Engine.ActionQueue.ExecuteActions()
at NHibernate.Event.Default.AbstractFlushingEventListener.PerformExecutions(IEventSource session)
2013-09-05 13:47:33,861 DEBUG [Agent: adapter run thread for test 'TestDemoBug' with id 'a769cf8d-dc3d-408c-b384-51c510aaf050'] [NHibernate.AdoNet.ConnectionManager] - registering flush end
2013-09-05 13:47:33,861 ERROR [Agent: adapter run thread for test 'TestDemoBug' with id 'a769cf8d-dc3d-408c-b384-51c510aaf050'] [NHibernate.Test.DemoBugUnitTest] - The bug still exists
NHibernate.StaleStateException: Batch update returned unexpected row count from update; actual row count: 0; expected: 2
at NHibernate.AdoNet.Expectations.VerifyOutcomeBatched(Int32 expectedRowCount, Int32 rowCount)
at NHibernate.AdoNet.SqlClientBatchingBatcher.DoExecuteBatch(IDbCommand ps)
at NHibernate.AdoNet.AbstractBatcher.ExecuteBatchWithTiming(IDbCommand ps)
at NHibernate.AdoNet.AbstractBatcher.ExecuteBatch()
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 NHibernate.Transaction.AdoTransaction.Commit()
at NHibernate.Test.DemoBugUnitTest.TestDemoBug() in C:\Development\NET\HVS\Forge\Research\NHibernate.BugTest\NHibernate.Test\DemoBugUnitTest.cs:line 110
Any comment for this issue? This is a very critical issue, NHibernate becomes unusable with this bug... My opinion, this is very important to fix.
Unable to save One-To-Many with Many-To-One relations. See attachments for more info. There is a README.TXT file with the details and a completed test projects for reproduce the issue.
Preject in the zip file created with NuGet, but as you wish I removed DLLs from the zip file.
Test project is a simple Visual Studio 2010 project. Requirements:
Iesi.Collections 3.2.0.4000
log4net 2.0.0 [1.2.11]
NHibernate 3.3.2.4000
NHibernate Mapping Attributes 3.2.0.0