Skip to content

Commit 13c7b3b

Browse files
committed
Test and fix for NH-3324
1 parent 99dcc98 commit 13c7b3b

File tree

5 files changed

+148
-3
lines changed

5 files changed

+148
-3
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
6+
namespace NHibernate.Test.NHSpecificTest.NH3324
7+
{
8+
internal class ChildEntity
9+
{
10+
public virtual int? Id { get; set; }
11+
public virtual string Name { get; set; }
12+
}
13+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
using System.Collections.Generic;
3+
4+
namespace NHibernate.Test.NHSpecificTest.NH3324
5+
{
6+
internal class Entity
7+
{
8+
public Entity()
9+
{
10+
Children = new List<ChildEntity>();
11+
}
12+
13+
public virtual int? Id { get; set; }
14+
public virtual string Name { get; set; }
15+
public virtual IList<ChildEntity> Children { get; set; }
16+
}
17+
}
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
using NHibernate.Cfg.MappingSchema;
2+
using NHibernate.Mapping.ByCode;
3+
using NUnit.Framework;
4+
5+
namespace NHibernate.Test.NHSpecificTest.NH3324
6+
{
7+
public class FixtureByCode : TestCaseMappingByCode
8+
{
9+
[Test]
10+
public void LeftOuterJoin()
11+
{
12+
using (var session = OpenSession())
13+
using (session.BeginTransaction())
14+
{
15+
const string hql = "FROM Entity e LEFT OUTER JOIN FETCH e.Children";
16+
17+
var query = session.CreateQuery(hql);
18+
var result = query.List(); // does work
19+
Assert.That(result, Has.Count.GreaterThan(0));
20+
}
21+
}
22+
23+
[Test]
24+
public void LeftOuterJoinSetMaxResults()
25+
{
26+
using (var session = OpenSession())
27+
using (session.BeginTransaction())
28+
{
29+
const string hql = "FROM Entity e LEFT OUTER JOIN FETCH e.Children";
30+
31+
var query = session.CreateQuery(hql);
32+
query.SetMaxResults(5);
33+
var result = query.List(); // does not work
34+
Assert.That(result, Has.Count.GreaterThan(0));
35+
}
36+
}
37+
38+
protected override HbmMapping GetMappings()
39+
{
40+
var mapper = new ModelMapper();
41+
42+
mapper.Class<Entity>(rc =>
43+
{
44+
rc.Id(x => x.Id,
45+
m =>
46+
{
47+
m.Generator(Generators.Identity);
48+
m.Length(4);
49+
});
50+
rc.Property(x => x.Name);
51+
rc.Bag(x => x.Children,
52+
c =>
53+
{
54+
c.Key(k =>
55+
{
56+
k.Column("EntityId");
57+
k.NotNullable(false);
58+
k.ForeignKey("Id");
59+
});
60+
c.Cascade(Mapping.ByCode.Cascade.All);
61+
c.Table("ChildEntity");
62+
c.Inverse(true);
63+
},
64+
t => t.OneToMany());
65+
});
66+
67+
mapper.Class<ChildEntity>(rc =>
68+
{
69+
rc.Id(x => x.Id,
70+
m =>
71+
{
72+
m.Generator(Generators.Identity);
73+
m.Length(4);
74+
});
75+
rc.Property(x => x.Name);
76+
});
77+
78+
return mapper.CompileMappingForAllExplicitlyAddedEntities();
79+
}
80+
81+
protected override void OnSetUp()
82+
{
83+
using (var session = OpenSession())
84+
using (var transaction = session.BeginTransaction())
85+
{
86+
var e1 = new Entity { Name = "Bob" };
87+
e1.Children.Add(new ChildEntity { Name = "Bob's Child" });
88+
session.Save(e1);
89+
90+
var e2 = new Entity { Name = "Sally" };
91+
e2.Children.Add(new ChildEntity { Name = "Sally's Child" });
92+
session.Save(e2);
93+
94+
session.Flush();
95+
transaction.Commit();
96+
}
97+
}
98+
99+
protected override void OnTearDown()
100+
{
101+
using (var session = OpenSession())
102+
using (var transaction = session.BeginTransaction())
103+
{
104+
session.Delete("from System.Object");
105+
106+
session.Flush();
107+
transaction.Commit();
108+
}
109+
}
110+
}
111+
}

src/NHibernate.Test/NHibernate.Test.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,9 @@
670670
<Compile Include="NHSpecificTest\NH2297\Entity.cs" />
671671
<Compile Include="NHSpecificTest\NH2297\Fixture.cs" />
672672
<Compile Include="NHSpecificTest\NH2297\InvalidCustomCompositeUserTypeBase.cs" />
673+
<Compile Include="NHSpecificTest\NH3324\ChildEntity.cs" />
674+
<Compile Include="NHSpecificTest\NH3324\Entity.cs" />
675+
<Compile Include="NHSpecificTest\NH3324\FixtureByCode.cs" />
673676
<Compile Include="NHSpecificTest\NH3374\Document.cs" />
674677
<Compile Include="NHSpecificTest\NH3374\FixtureByCode.cs" />
675678
<Compile Include="NHSpecificTest\NH2042\Model.cs" />
@@ -2873,6 +2876,7 @@
28732876
<EmbeddedResource Include="NHSpecificTest\NH1291AnonExample\Mappings.hbm.xml" />
28742877
</ItemGroup>
28752878
<ItemGroup>
2879+
<Content Include="NHSpecificTest\NH3324\Mappings.hbm.xml" />
28762880
<EmbeddedResource Include="NHSpecificTest\NH2297\MappingsNames.hbm.xml" />
28772881
<EmbeddedResource Include="NHSpecificTest\NH2297\MappingsTypes.hbm.xml" />
28782882
<EmbeddedResource Include="NHSpecificTest\NH2042\Mappings.hbm.xml" />

src/NHibernate/Engine/QueryParameters.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,8 @@ public QueryParameters CreateCopyUsing(RowSelection selection)
205205
selection, IsReadOnlyInitialized, readOnly, Cacheable, CacheRegion, Comment, CollectionKeys,
206206
OptionalObject, OptionalEntityName, OptionalId, ResultTransformer)
207207
{
208-
ProcessedSql = ProcessedSql,
209-
ProcessedSqlParameters = ProcessedSqlParameters.ToList()
208+
ProcessedSql = ProcessedSql,
209+
ProcessedSqlParameters = ProcessedSqlParameters != null ? ProcessedSqlParameters.ToList() : null
210210
};
211211
return copy;
212212
}
@@ -216,4 +216,4 @@ public bool IsReadOnly(ISessionImplementor session)
216216
return IsReadOnlyInitialized ? ReadOnly : session.PersistenceContext.DefaultReadOnly;
217217
}
218218
}
219-
}
219+
}

0 commit comments

Comments
 (0)