Skip to content

Commit 25ad179

Browse files
Merge pull request #1720 from fubar-coder/issue/GH-1719
Fix cascade + one-to-one failing on null no-proxy association
2 parents 12fbe7b + 3c8abeb commit 25ad179

File tree

7 files changed

+335
-61
lines changed

7 files changed

+335
-61
lines changed
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
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;
12+
using System.Linq;
13+
using System.Text;
14+
15+
using NUnit.Framework;
16+
using NHibernate.Linq;
17+
18+
namespace NHibernate.Test.NHSpecificTest.GH1719
19+
{
20+
using System.Threading.Tasks;
21+
[TestFixture]
22+
public class FixtureAsync : BugTestCase
23+
{
24+
private static readonly Guid RootGuid = Guid.Parse("00000000-0000-0000-0000-000000000001");
25+
26+
protected override void OnSetUp()
27+
{
28+
using (var session = OpenSession())
29+
using (var transaction = session.BeginTransaction())
30+
{
31+
var rootEntry = new FileEntryEntity
32+
{
33+
Id = RootGuid,
34+
Name = "root",
35+
};
36+
37+
session.Save(rootEntry);
38+
39+
var rootText = new FileEntryEntity
40+
{
41+
Id = Guid.NewGuid(),
42+
ParentId = rootEntry.Id,
43+
Name = "text1.txt",
44+
};
45+
46+
var rootTextData = new FileDataEntity
47+
{
48+
Entry = rootText
49+
};
50+
51+
rootText.Data = rootTextData;
52+
53+
session.Save(rootText);
54+
session.Save(rootTextData);
55+
56+
var subEntry = new FileEntryEntity
57+
{
58+
Id = Guid.NewGuid(),
59+
ParentId = rootEntry.Id,
60+
Name = "test1",
61+
};
62+
63+
session.Save(subEntry);
64+
65+
var subText = new FileEntryEntity
66+
{
67+
Id = Guid.NewGuid(),
68+
ParentId = subEntry.Id,
69+
Name = "text1.txt",
70+
};
71+
72+
var subTextData = new FileDataEntity
73+
{
74+
Entry = subText
75+
};
76+
77+
subText.Data = subTextData;
78+
79+
session.Save(subText);
80+
session.Save(subTextData);
81+
82+
transaction.Commit();
83+
}
84+
}
85+
86+
protected override void OnTearDown()
87+
{
88+
using (var session = OpenSession())
89+
using (var transaction = session.BeginTransaction())
90+
{
91+
// Order is important and we need both queries so that we don't trigger the exception
92+
session.CreateQuery("delete from FileDataEntity").ExecuteUpdate();
93+
session.CreateQuery("delete from FileEntryEntity").ExecuteUpdate();
94+
95+
transaction.Commit();
96+
}
97+
}
98+
99+
[Test]
100+
public async Task TestDeleteAfterRecursiveQueriesAsync()
101+
{
102+
using (var session = OpenSession())
103+
using (var trans = session.BeginTransaction())
104+
{
105+
var path = new[] { "test1", "text1.txt" };
106+
var found = await (session.LoadAsync<FileEntryEntity>(RootGuid));
107+
foreach (var pathPart in path)
108+
{
109+
var next = await (session.Query<FileEntryEntity>()
110+
.SingleOrDefaultAsync(x => x.ParentId == found.Id && x.Name == pathPart));
111+
Assert.That(next, Is.Not.Null);
112+
found = next;
113+
}
114+
115+
await (session.DeleteAsync(found));
116+
await (trans.CommitAsync());
117+
}
118+
}
119+
}
120+
}
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.GH1719
4+
{
5+
public class FileDataEntity
6+
{
7+
public virtual Guid Id { get; set; }
8+
public virtual FileEntryEntity Entry { get; set; }
9+
}
10+
}
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.GH1719
4+
{
5+
public class FileEntryEntity
6+
{
7+
public virtual Guid Id { get; set; }
8+
public virtual Guid? ParentId { get; set; }
9+
public virtual string Name { get; set; }
10+
public virtual FileDataEntity Data { get; set; }
11+
}
12+
}
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
using System;
2+
using System.Linq;
3+
using System.Text;
4+
5+
using NUnit.Framework;
6+
7+
namespace NHibernate.Test.NHSpecificTest.GH1719
8+
{
9+
[TestFixture]
10+
public class Fixture : BugTestCase
11+
{
12+
private static readonly Guid RootGuid = Guid.Parse("00000000-0000-0000-0000-000000000001");
13+
14+
protected override void OnSetUp()
15+
{
16+
using (var session = OpenSession())
17+
using (var transaction = session.BeginTransaction())
18+
{
19+
var rootEntry = new FileEntryEntity
20+
{
21+
Id = RootGuid,
22+
Name = "root",
23+
};
24+
25+
session.Save(rootEntry);
26+
27+
var rootText = new FileEntryEntity
28+
{
29+
Id = Guid.NewGuid(),
30+
ParentId = rootEntry.Id,
31+
Name = "text1.txt",
32+
};
33+
34+
var rootTextData = new FileDataEntity
35+
{
36+
Entry = rootText
37+
};
38+
39+
rootText.Data = rootTextData;
40+
41+
session.Save(rootText);
42+
session.Save(rootTextData);
43+
44+
var subEntry = new FileEntryEntity
45+
{
46+
Id = Guid.NewGuid(),
47+
ParentId = rootEntry.Id,
48+
Name = "test1",
49+
};
50+
51+
session.Save(subEntry);
52+
53+
var subText = new FileEntryEntity
54+
{
55+
Id = Guid.NewGuid(),
56+
ParentId = subEntry.Id,
57+
Name = "text1.txt",
58+
};
59+
60+
var subTextData = new FileDataEntity
61+
{
62+
Entry = subText
63+
};
64+
65+
subText.Data = subTextData;
66+
67+
session.Save(subText);
68+
session.Save(subTextData);
69+
70+
transaction.Commit();
71+
}
72+
}
73+
74+
protected override void OnTearDown()
75+
{
76+
using (var session = OpenSession())
77+
using (var transaction = session.BeginTransaction())
78+
{
79+
// Order is important and we need both queries so that we don't trigger the exception
80+
session.CreateQuery("delete from FileDataEntity").ExecuteUpdate();
81+
session.CreateQuery("delete from FileEntryEntity").ExecuteUpdate();
82+
83+
transaction.Commit();
84+
}
85+
}
86+
87+
[Test]
88+
public void TestDeleteAfterRecursiveQueries()
89+
{
90+
using (var session = OpenSession())
91+
using (var trans = session.BeginTransaction())
92+
{
93+
var path = new[] { "test1", "text1.txt" };
94+
var found = session.Load<FileEntryEntity>(RootGuid);
95+
foreach (var pathPart in path)
96+
{
97+
var next = session.Query<FileEntryEntity>()
98+
.SingleOrDefault(x => x.ParentId == found.Id && x.Name == pathPart);
99+
Assert.That(next, Is.Not.Null);
100+
found = next;
101+
}
102+
103+
session.Delete(found);
104+
trans.Commit();
105+
}
106+
}
107+
}
108+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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.GH1719">
4+
5+
<class name="FileEntryEntity" table="gh1719_entries">
6+
<id name="Id" column="id" generator="assigned" />
7+
<property name="ParentId" column="parent_id" />
8+
<property name="Name" column="name" length="50" not-null="true" />
9+
<one-to-one name="Data" lazy="no-proxy" cascade="all-delete-orphan" />
10+
</class>
11+
12+
<class name="FileDataEntity" table="gh1719_entrydata">
13+
<id name="Id" column="id">
14+
<generator class="foreign">
15+
<param name="property">Entry</param>
16+
</generator>
17+
</id>
18+
<one-to-one name="Entry" constrained="true" foreign-key="fk_data_entry" />
19+
</class>
20+
21+
</hibernate-mapping>

0 commit comments

Comments
 (0)