From c68f07a63f9e84a43937ac4701b3e5ea7da9477f Mon Sep 17 00:00:00 2001 From: Roman Artiukhin Date: Sun, 11 Jun 2023 12:15:22 +0300 Subject: [PATCH 1/4] Test case --- .../NHSpecificTest/GH3288/Entity.cs | 31 ++++++++++++ .../GH3288/FetchAndCollectionJoinFixture.cs | 47 +++++++++++++++++++ .../NHSpecificTest/GH3288/Mappings.hbm.xml | 26 ++++++++++ 3 files changed, 104 insertions(+) create mode 100644 src/NHibernate.Test/NHSpecificTest/GH3288/Entity.cs create mode 100644 src/NHibernate.Test/NHSpecificTest/GH3288/FetchAndCollectionJoinFixture.cs create mode 100644 src/NHibernate.Test/NHSpecificTest/GH3288/Mappings.hbm.xml diff --git a/src/NHibernate.Test/NHSpecificTest/GH3288/Entity.cs b/src/NHibernate.Test/NHSpecificTest/GH3288/Entity.cs new file mode 100644 index 00000000000..0e917134d11 --- /dev/null +++ b/src/NHibernate.Test/NHSpecificTest/GH3288/Entity.cs @@ -0,0 +1,31 @@ +using System.Collections.Generic; + +namespace NHibernate.Test.NHSpecificTest.GH3288 +{ + class TopEntity + { + public virtual int Id { get; set; } + public virtual MiddleEntity MiddleEntity { get; set; } + } + class MiddleEntity + { + public virtual int Id { get; set; } + public virtual ISet Components { get; set; } = new HashSet(); + } + + class Component + { + public virtual MiddleEntity MiddleEntity { get; set; } + public virtual int Value { get; set; } + + public override bool Equals(object obj) + { + return (obj as Component)?.MiddleEntity.Id == MiddleEntity.Id; + } + + public override int GetHashCode() + { + return MiddleEntity.Id.GetHashCode(); + } + } +} diff --git a/src/NHibernate.Test/NHSpecificTest/GH3288/FetchAndCollectionJoinFixture.cs b/src/NHibernate.Test/NHSpecificTest/GH3288/FetchAndCollectionJoinFixture.cs new file mode 100644 index 00000000000..440c4f772bd --- /dev/null +++ b/src/NHibernate.Test/NHSpecificTest/GH3288/FetchAndCollectionJoinFixture.cs @@ -0,0 +1,47 @@ +using System.Linq; +using NHibernate.Linq; +using NUnit.Framework; + +namespace NHibernate.Test.NHSpecificTest.GH3288 +{ + [TestFixture] + public class FetchAndCollectionJoinFixture : BugTestCase + { + protected override void OnSetUp() + { + using var session = OpenSession(); + using var transaction = session.BeginTransaction(); + var middleEntity = new MiddleEntity(); + middleEntity.Components.Add(new Component { MiddleEntity = middleEntity, Value = 1 }); + var te = new TopEntity + { + MiddleEntity = middleEntity + }; + session.Save(middleEntity); + session.Save(te); + + transaction.Commit(); + } + + protected override void OnTearDown() + { + using var session = OpenSession(); + using var transaction = session.BeginTransaction(); + session.Delete("from System.Object"); + + transaction.Commit(); + } + + [Test] + public void ReuseEntityJoinWithCollectionJoin() + { + using var session = OpenSession(); + + var entities = session.Query() + .Fetch(e => e.MiddleEntity) + .Where(e => e.MiddleEntity.Components.Any(e => e.Value != 0)) + .ToList(); + Assert.That(entities.Count, Is.EqualTo(1)); + } + } +} diff --git a/src/NHibernate.Test/NHSpecificTest/GH3288/Mappings.hbm.xml b/src/NHibernate.Test/NHSpecificTest/GH3288/Mappings.hbm.xml new file mode 100644 index 00000000000..2e5a43b00d9 --- /dev/null +++ b/src/NHibernate.Test/NHSpecificTest/GH3288/Mappings.hbm.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + From bb6d25aeebe78e60f4e9838b8c7417a613add403 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sun, 11 Jun 2023 09:20:16 +0000 Subject: [PATCH 2/4] Generate async files --- .../GH3288/FetchAndCollectionJoinFixture.cs | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/NHibernate.Test/Async/NHSpecificTest/GH3288/FetchAndCollectionJoinFixture.cs diff --git a/src/NHibernate.Test/Async/NHSpecificTest/GH3288/FetchAndCollectionJoinFixture.cs b/src/NHibernate.Test/Async/NHSpecificTest/GH3288/FetchAndCollectionJoinFixture.cs new file mode 100644 index 00000000000..0a1d6d97655 --- /dev/null +++ b/src/NHibernate.Test/Async/NHSpecificTest/GH3288/FetchAndCollectionJoinFixture.cs @@ -0,0 +1,58 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by AsyncGenerator. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + + +using System.Linq; +using NHibernate.Linq; +using NUnit.Framework; + +namespace NHibernate.Test.NHSpecificTest.GH3288 +{ + using System.Threading.Tasks; + [TestFixture] + public class FetchAndCollectionJoinFixtureAsync : BugTestCase + { + protected override void OnSetUp() + { + using var session = OpenSession(); + using var transaction = session.BeginTransaction(); + var middleEntity = new MiddleEntity(); + middleEntity.Components.Add(new Component { MiddleEntity = middleEntity, Value = 1 }); + var te = new TopEntity + { + MiddleEntity = middleEntity + }; + session.Save(middleEntity); + session.Save(te); + + transaction.Commit(); + } + + protected override void OnTearDown() + { + using var session = OpenSession(); + using var transaction = session.BeginTransaction(); + session.Delete("from System.Object"); + + transaction.Commit(); + } + + [Test] + public async Task ReuseEntityJoinWithCollectionJoinAsync() + { + using var session = OpenSession(); + + var entities = await (session.Query() + .Fetch(e => e.MiddleEntity) + .Where(e => e.MiddleEntity.Components.Any(e => e.Value != 0)) + .ToListAsync()); + Assert.That(entities.Count, Is.EqualTo(1)); + } + } +} From 70d3c702a84c70b833869438ed02c2e86f710b28 Mon Sep 17 00:00:00 2001 From: Roman Artiukhin Date: Sun, 11 Jun 2023 12:41:03 +0300 Subject: [PATCH 3/4] Fix --- src/NHibernate/Hql/Ast/ANTLR/HqlSqlWalker.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/NHibernate/Hql/Ast/ANTLR/HqlSqlWalker.cs b/src/NHibernate/Hql/Ast/ANTLR/HqlSqlWalker.cs index 2b2423d85bb..0982c4fdaee 100644 --- a/src/NHibernate/Hql/Ast/ANTLR/HqlSqlWalker.cs +++ b/src/NHibernate/Hql/Ast/ANTLR/HqlSqlWalker.cs @@ -527,7 +527,7 @@ internal string GetEntitySuffix(FromElement fromElement) internal string GetCollectionSuffix(FromElement fromElement) { - if (!fromElement.CollectionJoin && fromElement.QueryableCollection == null) + if (fromElement.QueryableCollection == null) { return null; } From 9b27c12b28a7e6e76d50d725a9f3828f274ecd4e Mon Sep 17 00:00:00 2001 From: Roman Artiukhin Date: Sun, 11 Jun 2023 13:03:41 +0300 Subject: [PATCH 4/4] Fix firebird --- src/NHibernate.Test/NHSpecificTest/GH3288/Mappings.hbm.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/NHibernate.Test/NHSpecificTest/GH3288/Mappings.hbm.xml b/src/NHibernate.Test/NHSpecificTest/GH3288/Mappings.hbm.xml index 2e5a43b00d9..94ca5e12a95 100644 --- a/src/NHibernate.Test/NHSpecificTest/GH3288/Mappings.hbm.xml +++ b/src/NHibernate.Test/NHSpecificTest/GH3288/Mappings.hbm.xml @@ -19,7 +19,7 @@ - +