Skip to content

Commit 58ae842

Browse files
fredericDelaportegcesena
andauthored
Remove class baseType interfaces from proxified methods (#1630)
Revert the lazy property proxy to its 5.0.x behavior. This allows to avoid proxifying explicitly implemented interface methods, which are currently not supported by the dynamix proxy (lazy properties proxy). Add test case adapted from gcesena test case. Fixes #1628 Co-authored-by: gcesena <[email protected]>
1 parent 5e01113 commit 58ae842

File tree

5 files changed

+161
-1
lines changed

5 files changed

+161
-1
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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 NUnit.Framework;
12+
13+
namespace NHibernate.Test.NHSpecificTest.GH1628
14+
{
15+
using System.Threading.Tasks;
16+
[TestFixture]
17+
public class FixtureAsync : BugTestCase
18+
{
19+
protected override void OnSetUp()
20+
{
21+
using (var session = OpenSession())
22+
using (var transaction = session.BeginTransaction())
23+
{
24+
var e1 = new Entity
25+
{
26+
Id = 1,
27+
Name = "Bob",
28+
ALongText = "Bob's very long text"
29+
};
30+
session.Save(e1);
31+
32+
var e2 = new Entity
33+
{
34+
Id = 2,
35+
Name = "Sally",
36+
ALongText = "Sally's very long text"
37+
};
38+
session.Save(e2);
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+
// The HQL delete does all the job inside the database without loading the entities, but it does
50+
// not handle delete order for avoiding violating constraints if any. Use
51+
// session.Delete("from System.Object");
52+
// instead if in need of having NHbernate ordering the deletes, but this will cause
53+
// loading the entities in the session.
54+
session.CreateQuery("delete from System.Object").ExecuteUpdate();
55+
56+
transaction.Commit();
57+
}
58+
}
59+
60+
[Test]
61+
public async Task ShouldNotThrowStackOverflowExceptionAsync()
62+
{
63+
using (var session = OpenSession())
64+
using (session.BeginTransaction())
65+
{
66+
IEntity result = await (session.GetAsync<Entity>(2));
67+
Assert.That(result, Is.Not.Null);
68+
Assert.That(result.Thing, Is.Null);
69+
}
70+
}
71+
}
72+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
namespace NHibernate.Test.NHSpecificTest.GH1628
2+
{
3+
public interface IEntity
4+
{
5+
object Thing { get; }
6+
}
7+
8+
public class Entity : IEntity
9+
{
10+
public virtual int Id { get; set; }
11+
12+
object IEntity.Thing { get { return null; } }
13+
public virtual string Name { get; set; }
14+
public virtual string ALongText { get; set; }
15+
}
16+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
using NUnit.Framework;
2+
3+
namespace NHibernate.Test.NHSpecificTest.GH1628
4+
{
5+
[TestFixture]
6+
public class Fixture : BugTestCase
7+
{
8+
protected override void OnSetUp()
9+
{
10+
using (var session = OpenSession())
11+
using (var transaction = session.BeginTransaction())
12+
{
13+
var e1 = new Entity
14+
{
15+
Id = 1,
16+
Name = "Bob",
17+
ALongText = "Bob's very long text"
18+
};
19+
session.Save(e1);
20+
21+
var e2 = new Entity
22+
{
23+
Id = 2,
24+
Name = "Sally",
25+
ALongText = "Sally's very long text"
26+
};
27+
session.Save(e2);
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+
// The HQL delete does all the job inside the database without loading the entities, but it does
39+
// not handle delete order for avoiding violating constraints if any. Use
40+
// session.Delete("from System.Object");
41+
// instead if in need of having NHbernate ordering the deletes, but this will cause
42+
// loading the entities in the session.
43+
session.CreateQuery("delete from System.Object").ExecuteUpdate();
44+
45+
transaction.Commit();
46+
}
47+
}
48+
49+
[Test]
50+
public void ShouldNotThrowStackOverflowException()
51+
{
52+
using (var session = OpenSession())
53+
using (session.BeginTransaction())
54+
{
55+
IEntity result = session.Get<Entity>(2);
56+
Assert.That(result, Is.Not.Null);
57+
Assert.That(result.Thing, Is.Null);
58+
}
59+
}
60+
}
61+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="NHibernate.Test"
3+
namespace="NHibernate.Test.NHSpecificTest.GH1628">
4+
5+
<class name="Entity">
6+
<id name="Id" generator="assigned"/>
7+
<property name="Name"/>
8+
<property name="ALongText" lazy="true"/>
9+
</class>
10+
11+
</hibernate-mapping>

src/NHibernate/Proxy/DynamicProxy/ProxyFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ private TypeInfo CreateUncachedProxyType(System.Type baseType, IReadOnlyCollecti
9898
{
9999
parentType = typeof (ProxyDummy);
100100
interfaces.Add(baseType);
101+
interfaces.UnionWith(baseType.GetInterfaces());
101102
}
102-
interfaces.UnionWith(baseType.GetInterfaces());
103103

104104
// Add the ISerializable interface so that it can be implemented
105105
interfaces.Add(typeof (ISerializable));

0 commit comments

Comments
 (0)