Skip to content

Commit 4727c0c

Browse files
Fix #3113 (#3137)
Co-authored-by: Roman Artiukhin <bahusdrive@gmail.com>
1 parent d903bb2 commit 4727c0c

File tree

4 files changed

+186
-6
lines changed

4 files changed

+186
-6
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
//------------------------------------------------------------------------------
2+
// <auto-generated>
3+
// This code was generated by AsyncGenerator.
4+
//
5+
// Changes to this file may cause incorrect behavior and will be lost if
6+
// the code is regenerated.
7+
// </auto-generated>
8+
//------------------------------------------------------------------------------
9+
10+
11+
using System.Linq;
12+
using NHibernate.Cfg;
13+
using NHibernate.Cfg.MappingSchema;
14+
using NHibernate.Dialect;
15+
using NHibernate.Mapping.ByCode;
16+
using NUnit.Framework;
17+
using NHibernate.Linq;
18+
19+
namespace NHibernate.Test.NHSpecificTest.GH3113
20+
{
21+
using System.Threading.Tasks;
22+
[TestFixture]
23+
public class ByCodeFixtureAsync : TestCaseMappingByCode
24+
{
25+
protected override HbmMapping GetMappings()
26+
{
27+
var mapper = new ModelMapper();
28+
mapper.Class<Entity>(rc =>
29+
{
30+
rc.Id(x => x.Id, m => m.Generator(Generators.GuidComb));
31+
rc.Property(x => x.Name);
32+
});
33+
34+
return mapper.CompileMappingForAllExplicitlyAddedEntities();
35+
}
36+
37+
protected override bool AppliesTo(Dialect.Dialect dialect)
38+
{
39+
return dialect is Oracle9iDialect;
40+
}
41+
42+
protected override void Configure(Configuration configuration)
43+
{
44+
var dialect = NHibernate.Dialect.Dialect.GetDialect(configuration.Properties);
45+
if (dialect is Oracle8iDialect)
46+
configuration.SetProperty(Environment.Dialect, typeof(Oracle9iDialect).FullName);
47+
48+
base.Configure(configuration);
49+
}
50+
51+
protected override void OnSetUp()
52+
{
53+
using (var session = OpenSession())
54+
using (var transaction = session.BeginTransaction())
55+
{
56+
var e1 = new Entity { Name = "Bob" };
57+
session.Save(e1);
58+
59+
var e2 = new Entity { Name = "Sally" };
60+
session.Save(e2);
61+
62+
transaction.Commit();
63+
}
64+
}
65+
66+
protected override void OnTearDown()
67+
{
68+
using (var session = OpenSession())
69+
using (var transaction = session.BeginTransaction())
70+
{
71+
session.CreateQuery("delete from System.Object").ExecuteUpdate();
72+
73+
transaction.Commit();
74+
}
75+
}
76+
77+
[Test]
78+
public async Task JoinFailsOnOracle9DialectAsync()
79+
{
80+
using (var session = OpenSession())
81+
{
82+
var result = from e in session.Query<Entity>()
83+
join e2 in session.Query<Entity>() on e.Id equals e2.Id
84+
where e.Name == "Bob"
85+
select e.Name;
86+
87+
Assert.That(await (result.ToListAsync()), Has.Count.EqualTo(1));
88+
}
89+
}
90+
}
91+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System;
2+
3+
namespace NHibernate.Test.NHSpecificTest.GH3113
4+
{
5+
class Entity
6+
{
7+
public virtual Guid Id { get; set; }
8+
public virtual string Name { get; set; }
9+
}
10+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
using System.Linq;
2+
using NHibernate.Cfg;
3+
using NHibernate.Cfg.MappingSchema;
4+
using NHibernate.Dialect;
5+
using NHibernate.Mapping.ByCode;
6+
using NUnit.Framework;
7+
8+
namespace NHibernate.Test.NHSpecificTest.GH3113
9+
{
10+
[TestFixture]
11+
public class ByCodeFixture : TestCaseMappingByCode
12+
{
13+
protected override HbmMapping GetMappings()
14+
{
15+
var mapper = new ModelMapper();
16+
mapper.Class<Entity>(rc =>
17+
{
18+
rc.Id(x => x.Id, m => m.Generator(Generators.GuidComb));
19+
rc.Property(x => x.Name);
20+
});
21+
22+
return mapper.CompileMappingForAllExplicitlyAddedEntities();
23+
}
24+
25+
protected override bool AppliesTo(Dialect.Dialect dialect)
26+
{
27+
return dialect is Oracle9iDialect;
28+
}
29+
30+
protected override void Configure(Configuration configuration)
31+
{
32+
var dialect = NHibernate.Dialect.Dialect.GetDialect(configuration.Properties);
33+
if (dialect is Oracle8iDialect)
34+
configuration.SetProperty(Environment.Dialect, typeof(Oracle9iDialect).FullName);
35+
36+
base.Configure(configuration);
37+
}
38+
39+
protected override void OnSetUp()
40+
{
41+
using (var session = OpenSession())
42+
using (var transaction = session.BeginTransaction())
43+
{
44+
var e1 = new Entity { Name = "Bob" };
45+
session.Save(e1);
46+
47+
var e2 = new Entity { Name = "Sally" };
48+
session.Save(e2);
49+
50+
transaction.Commit();
51+
}
52+
}
53+
54+
protected override void OnTearDown()
55+
{
56+
using (var session = OpenSession())
57+
using (var transaction = session.BeginTransaction())
58+
{
59+
session.CreateQuery("delete from System.Object").ExecuteUpdate();
60+
61+
transaction.Commit();
62+
}
63+
}
64+
65+
[Test]
66+
public void JoinFailsOnOracle9Dialect()
67+
{
68+
using (var session = OpenSession())
69+
{
70+
var result = from e in session.Query<Entity>()
71+
join e2 in session.Query<Entity>() on e.Id equals e2.Id
72+
where e.Name == "Bob"
73+
select e.Name;
74+
75+
Assert.That(result.ToList(), Has.Count.EqualTo(1));
76+
}
77+
}
78+
}
79+
}

src/NHibernate/Hql/Ast/ANTLR/Util/JoinProcessor.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,14 @@ private void AddJoinNodes(IRestrictableStatement query, JoinSequence join, FromE
117117
SqlString frag = joinFragment.ToFromFragmentString;
118118
SqlString whereFrag = joinFragment.ToWhereFragmentString;
119119

120-
// If the from element represents a JOIN_FRAGMENT and it is
121-
// a theta-style join, convert its type from JOIN_FRAGMENT
122-
// to FROM_FRAGMENT
123-
if ( fromElement.Type == HqlSqlWalker.JOIN_FRAGMENT &&
124-
( join.IsThetaStyle || SqlStringHelper.IsNotEmpty( whereFrag ) ) )
120+
// If the from element represents a JOIN_FRAGMENT or ENTITY_JOIN and it is
121+
// a theta-style join, convert its type to FROM_FRAGMENT.
122+
if ((fromElement.Type == HqlSqlWalker.JOIN_FRAGMENT || fromElement.Type == HqlSqlWalker.ENTITY_JOIN) &&
123+
(join.IsThetaStyle || SqlStringHelper.IsNotEmpty(whereFrag)))
125124
{
126125
fromElement.Type = HqlSqlWalker.FROM_FRAGMENT;
127-
fromElement.JoinSequence.SetUseThetaStyle( true ); // this is used during SqlGenerator processing
126+
// This is used during SqlGenerator processing.
127+
fromElement.JoinSequence.SetUseThetaStyle(true);
128128
}
129129

130130
// If there is a FROM fragment and the FROM element is an explicit, then add the from part.

0 commit comments

Comments
 (0)