Skip to content

Commit d8a061b

Browse files
Merge 5.3.14 into master
2 parents 6f886d3 + 37b5020 commit d8a061b

File tree

12 files changed

+314
-9
lines changed

12 files changed

+314
-9
lines changed

releasenotes.txt

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,21 @@
1-
Build 5.3.13
1+
Build 5.3.14
2+
=============================
3+
4+
Release notes - NHibernate - Version 5.3.14
5+
6+
3 issues were resolved in this release.
7+
8+
** Bug
9+
10+
#3169 InvalidOperationException: This transformer is not initialized by Cached Query
11+
#3164 Fetching a lazy loaded component regression
12+
13+
** Task
14+
15+
* #3183 Release 5.3.14
16+
17+
18+
Build 5.3.13
219
=============================
320

421
Release notes - NHibernate - Version 5.3.13
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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.MappingSchema;
13+
using NHibernate.Mapping.ByCode;
14+
using NUnit.Framework;
15+
using NHibernate.Linq;
16+
17+
namespace NHibernate.Test.NHSpecificTest.GH3164
18+
{
19+
using System.Threading.Tasks;
20+
[TestFixture]
21+
public class ByCodeFixtureAsync : TestCaseMappingByCode
22+
{
23+
protected override HbmMapping GetMappings()
24+
{
25+
var mapper = new ModelMapper();
26+
mapper.AddMapping<ContentItemMapping>();
27+
mapper.AddMapping<HeadMapping>();
28+
29+
return mapper.CompileMappingForAllExplicitlyAddedEntities();
30+
}
31+
32+
protected override void OnSetUp()
33+
{
34+
using (var session = OpenSession())
35+
using (var transaction = session.BeginTransaction())
36+
{
37+
var e1 = new ContentItem { Name = "Test" };
38+
session.Save(e1);
39+
40+
transaction.Commit();
41+
}
42+
}
43+
44+
protected override void OnTearDown()
45+
{
46+
using (var session = OpenSession())
47+
using (var transaction = session.BeginTransaction())
48+
{
49+
session.CreateQuery("delete from System.Object").ExecuteUpdate();
50+
51+
transaction.Commit();
52+
}
53+
}
54+
55+
[Test]
56+
public async Task FetchComponentAsync()
57+
{
58+
using (var session = OpenSession())
59+
{
60+
var result = await (session.Query<ContentItem>().Fetch(i => i.Head).ToListAsync());
61+
62+
Assert.That(result.Count, Is.EqualTo(1));
63+
}
64+
}
65+
}
66+
}

src/NHibernate.Test/Async/SqlTest/Query/NativeSQLQueriesFixture.cs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,55 @@ Task<IList> GetCacheableSqlQueryResultsAsync()
282282
}
283283
}
284284

285+
class ResultDto
286+
{
287+
public string regionCode { get; set; }
288+
}
289+
290+
[Test(Description = "GH-3169")]
291+
public async Task CacheableScalarSQLQueryWithTransformerAsync()
292+
{
293+
Organization ifa = new Organization("IFA");
294+
295+
using (ISession s = OpenSession())
296+
using (ITransaction t = s.BeginTransaction())
297+
{
298+
await (s.SaveAsync(ifa));
299+
await (t.CommitAsync());
300+
}
301+
302+
async Task AssertQueryAsync(bool fromCache)
303+
{
304+
using (var s = OpenSession())
305+
using (var t = s.BeginTransaction())
306+
using (EnableStatisticsScope())
307+
{
308+
var l = await (s.CreateSQLQuery("select org.NAME as regionCode from ORGANIZATION org")
309+
.AddScalar("regionCode", NHibernateUtil.String)
310+
.SetResultTransformer(Transformers.AliasToBean<ResultDto>())
311+
.SetCacheable(true)
312+
.ListAsync());
313+
await (t.CommitAsync());
314+
315+
Assert.AreEqual(1, l.Count);
316+
//TODO: Uncomment if we properly fix caching auto discovery type queries with transformers
317+
// var msg = "results are expected from " + (fromCache ? "cache" : "DB");
318+
// Assert.That(Sfi.Statistics.QueryCacheMissCount, Is.EqualTo(fromCache ? 0 : 1), msg);
319+
// Assert.That(Sfi.Statistics.QueryCacheHitCount, Is.EqualTo(fromCache ? 1 : 0), msg);
320+
}
321+
}
322+
323+
await (AssertQueryAsync(false));
324+
await (AssertQueryAsync(true));
325+
326+
using (var s = OpenSession())
327+
using (var t = s.BeginTransaction())
328+
{
329+
await (s.DeleteAsync(ifa));
330+
await (t.CommitAsync());
331+
}
332+
}
333+
285334
[Test]
286335
public async Task ResultSetMappingDefinitionAsync()
287336
{
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace NHibernate.Test.NHSpecificTest.GH3164
2+
{
3+
public class ContentItem
4+
{
5+
public virtual int Id { get; set; }
6+
public virtual string Name { get; set; }
7+
public virtual IHead Head { get; set; }
8+
}
9+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using NHibernate.Mapping.ByCode;
2+
using NHibernate.Mapping.ByCode.Conformist;
3+
4+
namespace NHibernate.Test.NHSpecificTest.GH3164
5+
{
6+
public class ContentItemMapping : ClassMapping<ContentItem>
7+
{
8+
public ContentItemMapping()
9+
{
10+
Table("ContentItems");
11+
Id(x => x.Id, m => m.Generator(Generators.Identity));
12+
Property(x => x.Name);
13+
Component(x => x.Head, x => x.Lazy(true));
14+
}
15+
}
16+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using System.Linq;
2+
using NHibernate.Cfg.MappingSchema;
3+
using NHibernate.Mapping.ByCode;
4+
using NUnit.Framework;
5+
using NHibernate.Linq;
6+
7+
namespace NHibernate.Test.NHSpecificTest.GH3164
8+
{
9+
[TestFixture]
10+
public class ByCodeFixture : TestCaseMappingByCode
11+
{
12+
protected override HbmMapping GetMappings()
13+
{
14+
var mapper = new ModelMapper();
15+
mapper.AddMapping<ContentItemMapping>();
16+
mapper.AddMapping<HeadMapping>();
17+
18+
return mapper.CompileMappingForAllExplicitlyAddedEntities();
19+
}
20+
21+
protected override void OnSetUp()
22+
{
23+
using (var session = OpenSession())
24+
using (var transaction = session.BeginTransaction())
25+
{
26+
var e1 = new ContentItem { Name = "Test" };
27+
session.Save(e1);
28+
29+
transaction.Commit();
30+
}
31+
}
32+
33+
protected override void OnTearDown()
34+
{
35+
using (var session = OpenSession())
36+
using (var transaction = session.BeginTransaction())
37+
{
38+
session.CreateQuery("delete from System.Object").ExecuteUpdate();
39+
40+
transaction.Commit();
41+
}
42+
}
43+
44+
[Test]
45+
public void FetchComponent()
46+
{
47+
using (var session = OpenSession())
48+
{
49+
var result = session.Query<ContentItem>().Fetch(i => i.Head).ToList();
50+
51+
Assert.That(result.Count, Is.EqualTo(1));
52+
}
53+
}
54+
}
55+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
3+
namespace NHibernate.Test.NHSpecificTest.GH3164
4+
{
5+
[Serializable]
6+
public class Head : IHead
7+
{
8+
public virtual string Title { get; set; }
9+
10+
public virtual bool DummyFieldToLoadEmptyComponent { get; }
11+
}
12+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using NHibernate.Mapping.ByCode;
2+
using NHibernate.Mapping.ByCode.Conformist;
3+
4+
namespace NHibernate.Test.NHSpecificTest.GH3164
5+
{
6+
public class HeadMapping : ComponentMapping<IHead>
7+
{
8+
public HeadMapping()
9+
{
10+
Class<Head>();
11+
Property(x => x.Title, m =>
12+
{
13+
m.Column("PageTitle");
14+
m.Lazy(true);
15+
});
16+
Property(x => x.DummyFieldToLoadEmptyComponent, m =>
17+
{
18+
m.Access(Accessor.ReadOnly);
19+
m.Formula("1");
20+
});
21+
Lazy(true);
22+
}
23+
}
24+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace NHibernate.Test.NHSpecificTest.GH3164
2+
{
3+
4+
public interface IHead
5+
{
6+
string Title { get; set; }
7+
8+
bool DummyFieldToLoadEmptyComponent { get; }
9+
}
10+
}

src/NHibernate.Test/SqlTest/Query/NativeSQLQueriesFixture.cs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,55 @@ IList GetCacheableSqlQueryResults()
264264
}
265265
}
266266

267+
class ResultDto
268+
{
269+
public string regionCode { get; set; }
270+
}
271+
272+
[Test(Description = "GH-3169")]
273+
public void CacheableScalarSQLQueryWithTransformer()
274+
{
275+
Organization ifa = new Organization("IFA");
276+
277+
using (ISession s = OpenSession())
278+
using (ITransaction t = s.BeginTransaction())
279+
{
280+
s.Save(ifa);
281+
t.Commit();
282+
}
283+
284+
void AssertQuery(bool fromCache)
285+
{
286+
using (var s = OpenSession())
287+
using (var t = s.BeginTransaction())
288+
using (EnableStatisticsScope())
289+
{
290+
var l = s.CreateSQLQuery("select org.NAME as regionCode from ORGANIZATION org")
291+
.AddScalar("regionCode", NHibernateUtil.String)
292+
.SetResultTransformer(Transformers.AliasToBean<ResultDto>())
293+
.SetCacheable(true)
294+
.List();
295+
t.Commit();
296+
297+
Assert.AreEqual(1, l.Count);
298+
//TODO: Uncomment if we properly fix caching auto discovery type queries with transformers
299+
// var msg = "results are expected from " + (fromCache ? "cache" : "DB");
300+
// Assert.That(Sfi.Statistics.QueryCacheMissCount, Is.EqualTo(fromCache ? 0 : 1), msg);
301+
// Assert.That(Sfi.Statistics.QueryCacheHitCount, Is.EqualTo(fromCache ? 1 : 0), msg);
302+
}
303+
}
304+
305+
AssertQuery(false);
306+
AssertQuery(true);
307+
308+
using (var s = OpenSession())
309+
using (var t = s.BeginTransaction())
310+
{
311+
s.Delete(ifa);
312+
t.Commit();
313+
}
314+
}
315+
267316
[Test]
268317
public void ResultSetMappingDefinition()
269318
{

0 commit comments

Comments
 (0)