Skip to content

Commit bb44579

Browse files
committed
WIP Table group joins support for subclasses with withClause in hql
1 parent 9427018 commit bb44579

14 files changed

+360
-196
lines changed

src/NHibernate.Test/Async/Hql/Ast/WithClauseFixture.cs

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88
//------------------------------------------------------------------------------
99

1010

11-
using System;
1211
using System.Collections;
13-
using NHibernate.Exceptions;
1412
using NHibernate.Hql.Ast.ANTLR;
1513
using NUnit.Framework;
1614

@@ -54,40 +52,21 @@ public async Task WithClauseFailsWithFetchAsync()
5452
}
5553

5654
[Test]
57-
public async Task ValidWithSemanticsAsync()
55+
public async Task WithClauseOnSubclassesAsync()
5856
{
5957
using (var s = OpenSession())
6058
{
6159
await (s.CreateQuery(
6260
"from Animal a inner join a.offspring o inner join o.mother as m inner join m.father as f with o.bodyWeight > 1").ListAsync());
63-
}
64-
}
6561

66-
[Test]
67-
public async Task InvalidWithSemanticsAsync()
68-
{
69-
using (ISession s = OpenSession())
70-
{
71-
// PROBLEM : f.bodyWeight is a reference to a column on the Animal table; however, the 'f'
72-
// alias relates to the Human.friends collection which the aonther Human entity. The issue
73-
// here is the way JoinSequence and Joinable (the persister) interact to generate the
74-
// joins relating to the sublcass/superclass tables
75-
Assert.ThrowsAsync<InvalidWithClauseException>(
76-
() =>
77-
s.CreateQuery("from Human h inner join h.friends as f with f.bodyWeight < :someLimit").SetDouble("someLimit", 1).ListAsync());
78-
79-
//The query below is no longer throw InvalidWithClauseException but generates "invalid" SQL to better support complex with join clauses.
80-
//Invalid SQL means that additional joins for "o.mother.father" are currently added after "offspring" join. Some DBs can process such query and some can't.
81-
try
82-
{
83-
await (s.CreateQuery("from Human h inner join h.offspring o with o.mother.father = :cousin")
84-
.SetInt32("cousin", 123)
85-
.ListAsync());
86-
}
87-
catch (GenericADOException)
88-
{
89-
//Apparently SQLite can process queries with wrong join orders
90-
}
62+
// f.bodyWeight is a reference to a column on the Animal table; however, the 'f'
63+
// alias relates to the Human.friends collection which the aonther Human entity.
64+
// Group join allows us to use such constructs
65+
await (s.CreateQuery("from Human h inner join h.friends as f with f.bodyWeight < :someLimit").SetDouble("someLimit", 1).ListAsync());
66+
67+
await (s.CreateQuery("from Human h inner join h.offspring o with o.mother.father = :cousin")
68+
.SetInt32("cousin", 123)
69+
.ListAsync());
9170
}
9271
}
9372

src/NHibernate.Test/Hql/Ast/WithClauseFixture.cs

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using System;
21
using System.Collections;
3-
using NHibernate.Exceptions;
42
using NHibernate.Hql.Ast.ANTLR;
53
using NUnit.Framework;
64

@@ -42,40 +40,21 @@ public void WithClauseFailsWithFetch()
4240
}
4341

4442
[Test]
45-
public void ValidWithSemantics()
43+
public void WithClauseOnSubclasses()
4644
{
4745
using (var s = OpenSession())
4846
{
4947
s.CreateQuery(
5048
"from Animal a inner join a.offspring o inner join o.mother as m inner join m.father as f with o.bodyWeight > 1").List();
51-
}
52-
}
5349

54-
[Test]
55-
public void InvalidWithSemantics()
56-
{
57-
using (ISession s = OpenSession())
58-
{
59-
// PROBLEM : f.bodyWeight is a reference to a column on the Animal table; however, the 'f'
60-
// alias relates to the Human.friends collection which the aonther Human entity. The issue
61-
// here is the way JoinSequence and Joinable (the persister) interact to generate the
62-
// joins relating to the sublcass/superclass tables
63-
Assert.Throws<InvalidWithClauseException>(
64-
() =>
65-
s.CreateQuery("from Human h inner join h.friends as f with f.bodyWeight < :someLimit").SetDouble("someLimit", 1).List());
66-
67-
//The query below is no longer throw InvalidWithClauseException but generates "invalid" SQL to better support complex with join clauses.
68-
//Invalid SQL means that additional joins for "o.mother.father" are currently added after "offspring" join. Some DBs can process such query and some can't.
69-
try
70-
{
71-
s.CreateQuery("from Human h inner join h.offspring o with o.mother.father = :cousin")
72-
.SetInt32("cousin", 123)
73-
.List();
74-
}
75-
catch (GenericADOException)
76-
{
77-
//Apparently SQLite can process queries with wrong join orders
78-
}
50+
// f.bodyWeight is a reference to a column on the Animal table; however, the 'f'
51+
// alias relates to the Human.friends collection which the aonther Human entity.
52+
// Group join allows us to use such constructs
53+
s.CreateQuery("from Human h inner join h.friends as f with f.bodyWeight < :someLimit").SetDouble("someLimit", 1).List();
54+
55+
s.CreateQuery("from Human h inner join h.offspring o with o.mother.father = :cousin")
56+
.SetInt32("cousin", 123)
57+
.List();
7958
}
8059
}
8160

0 commit comments

Comments
 (0)