From 344b7f3702eae46a7b8fde0b847dff50ce44fd07 Mon Sep 17 00:00:00 2001 From: Mihai <961778+mihaicodrean@users.noreply.github.com> Date: Sat, 23 Mar 2024 22:25:34 +0200 Subject: [PATCH 1/3] Inserting multiple associations of the same entity fails (#3489) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Frédéric Delaporte <12201973+fredericdelaporte@users.noreply.github.com> --- .../BulkManipulation/HQLBulkOperations.cs | 18 +++++++++++- .../BulkManipulation/Course.cs | 8 +++++ .../BulkManipulation/Enrolment.cs | 12 ++++++++ .../BulkManipulation/Enrolment.hbm.xml | 29 +++++++++++++++++++ .../BulkManipulation/HQLBulkOperations.cs | 18 +++++++++++- .../BulkManipulation/Student.cs | 8 +++++ .../Hql/Ast/ANTLR/Tree/SelectClause.cs | 2 +- 7 files changed, 92 insertions(+), 3 deletions(-) create mode 100644 src/NHibernate.Test/BulkManipulation/Course.cs create mode 100644 src/NHibernate.Test/BulkManipulation/Enrolment.cs create mode 100644 src/NHibernate.Test/BulkManipulation/Enrolment.hbm.xml create mode 100644 src/NHibernate.Test/BulkManipulation/Student.cs diff --git a/src/NHibernate.Test/Async/BulkManipulation/HQLBulkOperations.cs b/src/NHibernate.Test/Async/BulkManipulation/HQLBulkOperations.cs index 4dd0de91f8e..2bc13bba995 100644 --- a/src/NHibernate.Test/Async/BulkManipulation/HQLBulkOperations.cs +++ b/src/NHibernate.Test/Async/BulkManipulation/HQLBulkOperations.cs @@ -43,5 +43,21 @@ public async Task SimpleDeleteAsync() await (tx.CommitAsync()); } } + + [Test] + public async Task InsertFromSelectWithMultipleAssociationsAsync() + { + Assume.That(TestDialect.NativeGeneratorSupportsBulkInsertion, + "The dialect does not support a native generator compatible with bulk insertion."); + + using var s = OpenSession(); + using var tx = s.BeginTransaction(); + + await (s.CreateQuery("insert into Enrolment (Course, Student)" + + " select e.Course, e.Student from Enrolment e") + .ExecuteUpdateAsync()); + + await (tx.CommitAsync()); + } } -} \ No newline at end of file +} diff --git a/src/NHibernate.Test/BulkManipulation/Course.cs b/src/NHibernate.Test/BulkManipulation/Course.cs new file mode 100644 index 00000000000..0ceb699b8f6 --- /dev/null +++ b/src/NHibernate.Test/BulkManipulation/Course.cs @@ -0,0 +1,8 @@ +namespace NHibernate.Test.BulkManipulation +{ + public class Course + { + public virtual long CourseId { get; set; } + public virtual string Description { get; set; } + } +} diff --git a/src/NHibernate.Test/BulkManipulation/Enrolment.cs b/src/NHibernate.Test/BulkManipulation/Enrolment.cs new file mode 100644 index 00000000000..547ecd52640 --- /dev/null +++ b/src/NHibernate.Test/BulkManipulation/Enrolment.cs @@ -0,0 +1,12 @@ +using System; + +namespace NHibernate.Test.BulkManipulation +{ + [Serializable] + public class Enrolment + { + public virtual long EnrolmentId { get; set; } + public virtual Student Student { get; set; } + public virtual Course Course { get; set; } + } +} diff --git a/src/NHibernate.Test/BulkManipulation/Enrolment.hbm.xml b/src/NHibernate.Test/BulkManipulation/Enrolment.hbm.xml new file mode 100644 index 00000000000..84e6a0b293d --- /dev/null +++ b/src/NHibernate.Test/BulkManipulation/Enrolment.hbm.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/NHibernate.Test/BulkManipulation/HQLBulkOperations.cs b/src/NHibernate.Test/BulkManipulation/HQLBulkOperations.cs index 66883da2301..4338c5148b5 100644 --- a/src/NHibernate.Test/BulkManipulation/HQLBulkOperations.cs +++ b/src/NHibernate.Test/BulkManipulation/HQLBulkOperations.cs @@ -32,5 +32,21 @@ public void SimpleDelete() tx.Commit(); } } + + [Test] + public void InsertFromSelectWithMultipleAssociations() + { + Assume.That(TestDialect.NativeGeneratorSupportsBulkInsertion, + "The dialect does not support a native generator compatible with bulk insertion."); + + using var s = OpenSession(); + using var tx = s.BeginTransaction(); + + s.CreateQuery("insert into Enrolment (Course, Student)" + + " select e.Course, e.Student from Enrolment e") + .ExecuteUpdate(); + + tx.Commit(); + } } -} \ No newline at end of file +} diff --git a/src/NHibernate.Test/BulkManipulation/Student.cs b/src/NHibernate.Test/BulkManipulation/Student.cs new file mode 100644 index 00000000000..6dd9468adf3 --- /dev/null +++ b/src/NHibernate.Test/BulkManipulation/Student.cs @@ -0,0 +1,8 @@ +namespace NHibernate.Test.BulkManipulation +{ + public class Student + { + public virtual long StudentId { get; set; } + public virtual string Name { get; set; } + } +} diff --git a/src/NHibernate/Hql/Ast/ANTLR/Tree/SelectClause.cs b/src/NHibernate/Hql/Ast/ANTLR/Tree/SelectClause.cs index 6119f5642e7..00993891bba 100644 --- a/src/NHibernate/Hql/Ast/ANTLR/Tree/SelectClause.cs +++ b/src/NHibernate/Hql/Ast/ANTLR/Tree/SelectClause.cs @@ -494,7 +494,7 @@ private void RenderNonScalarIdentifiers( } var node = (IASTNode) e; - if (processedElements.Add(fromElement)) + if (Walker.IsShallowQuery && node.Type == SqlGenerator.DOT || processedElements.Add(fromElement)) { combinedFromElements.Add(fromElement); RenderNonScalarIdentifiers(fromElement, inheritedExpressions.ContainsKey(e) ? null : e, appender); From 16f71d2ec6d8b3246e3140985d5711775b670617 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Delaporte?= <12201973+fredericDelaporte@users.noreply.github.com> Date: Sat, 23 Mar 2024 21:33:07 +0100 Subject: [PATCH 2/3] Enable 5.4.8 dev builds --- build-common/NHibernate.props | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build-common/NHibernate.props b/build-common/NHibernate.props index b36961fc58a..1fab9ed8b19 100644 --- a/build-common/NHibernate.props +++ b/build-common/NHibernate.props @@ -3,9 +3,9 @@ 5.4 - 7 + 8 - + dev 9.0 $(NhVersion).$(VersionPatch) From b3256e7e585fc2f12bd42487d31e9c45eb748a7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Delaporte?= <12201973+fredericDelaporte@users.noreply.github.com> Date: Tue, 26 Mar 2024 20:21:49 +0100 Subject: [PATCH 3/3] Release 5.4.8 (#3507) --- build-common/NHibernate.props | 2 +- releasenotes.txt | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/build-common/NHibernate.props b/build-common/NHibernate.props index 1fab9ed8b19..a614470a18b 100644 --- a/build-common/NHibernate.props +++ b/build-common/NHibernate.props @@ -5,7 +5,7 @@ 5.4 8 - dev + 9.0 $(NhVersion).$(VersionPatch) diff --git a/releasenotes.txt b/releasenotes.txt index f9fbf217f26..2351054af6c 100644 --- a/releasenotes.txt +++ b/releasenotes.txt @@ -1,4 +1,20 @@ -Build 5.4.7 +Build 5.4.8 +============================= + +Release notes - NHibernate - Version 5.4.8 + +2 issues were resolved in this release. + +** Bug + + * #3489 Inserting multiple associations of the same entity fails + +** Task + + * #3507 Release 5.4.8 + + +Build 5.4.7 ============================= Release notes - NHibernate - Version 5.4.7