Closed
Description
My colleague was able to create a standalone repro for #2173, but since that issue was closed, I'm opening a new one.
Our software is seeing an inflated number of SQL statements being issued, in very particular situations, after upgrading from NHibernate 5.1.6 to 5.2.0+.
.NET Core 3.0 + SQLite repro source: nh-repro.zip
Program.Main()
contains 3 NH operations that together demonstrate the difference:
long startingStatementCount = sessionFactory.Statistics.PrepareStatementCount;
using (var session = sessionFactory.OpenSession())
using (session.BeginTransaction())
{
var parent = session.QueryOver<Parent>().List()[0];
session.Refresh(parent);
session.QueryOver<Parent>().Future().ToList();
}
Console.WriteLine($"SQL statements issued: {sessionFactory.Statistics.PrepareStatementCount - startingStatementCount}");
Executing the code using NH 5.1.6 shows the expected number of executed statements:
$ dotnet run -p nh-5.1.6
SQL statements issued: 3
NH 5.2.0 is the first version to show additional statements:
$ dotnet run -p nh-5.2.0
SQL statements issued: 7
NH 5.2.6 still exhibits the defect:
$ dotnet run -p nh-5.2.6
SQL statements issued: 7
Some conditions that appear to be required to reproduce the issue:
- The queries/refresh must be in a transaction
- The 2nd query must use
.Future()
- A related entity with a composite key, whose mapping from the first entity cascades both Refresh (or All) and DeleteOrphans
- Another related entity from that one that overrides Equals and GetHashCode