-
Notifications
You must be signed in to change notification settings - Fork 936
GH1149 one-to-one related object not loaded with stateless session #1620
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
fredericDelaporte
merged 8 commits into
nhibernate:master
from
seamus-hoban:GH1149-OneToOneStatelessSessionLoad
Mar 20, 2018
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
000849a
Fix for Stateless Session 1:1 loading.
seamus-hoban 8535c14
Remove .editorconfig and sln.DotSettings
seamus-hoban 7e3d168
Added One To One with foreign key test
seamus-hoban ce03a6e
Merge branch 'master' into GH1149-OneToOneStatelessSessionLoad
seamus-hoban 7d2fc4b
Remove obj.IsProxy check on foot of comment on PR.
seamus-hoban 7d787bd
Added Async tests.
seamus-hoban d610e1b
Revert changes.
seamus-hoban 7791ea2
Regen async.
fredericDelaporte File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
98 changes: 98 additions & 0 deletions
98
src/NHibernate.Test/Async/NHSpecificTest/GH1149/Fixture.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
//------------------------------------------------------------------------------ | ||
// <auto-generated> | ||
// This code was generated by AsyncGenerator. | ||
// | ||
// Changes to this file may cause incorrect behavior and will be lost if | ||
// the code is regenerated. | ||
// </auto-generated> | ||
//------------------------------------------------------------------------------ | ||
|
||
|
||
using NUnit.Framework; | ||
|
||
namespace NHibernate.Test.NHSpecificTest.GH1149 | ||
{ | ||
using System.Threading.Tasks; | ||
[TestFixture] | ||
public class FixtureAsync : BugTestCase | ||
{ | ||
protected override void OnTearDown() | ||
{ | ||
using (ISession session = OpenSession()) | ||
using (ITransaction transaction = session.BeginTransaction()) | ||
{ | ||
session.Delete("from Address"); | ||
session.Delete("from Company"); | ||
session.Delete("from AddressO2O"); | ||
session.Delete("from CompanyO2O"); | ||
session.Flush(); | ||
transaction.Commit(); | ||
} | ||
} | ||
|
||
[Test] | ||
public async Task StatelessSessionLoadsOneToOneRelatedObject_PropertyRefAsync() | ||
{ | ||
// Create and save company and address | ||
var companyId = 0; | ||
|
||
using (ISession session = OpenSession()) | ||
{ | ||
using (ITransaction tx = session.BeginTransaction()) | ||
{ | ||
var company = new Company { Name = "Test Company" }; | ||
|
||
company.Address = new Address(company) { AddressLine1 = "Company Address" }; | ||
|
||
companyId = (int) await (session.SaveAsync(company)); | ||
|
||
await (tx.CommitAsync()); | ||
} | ||
} | ||
|
||
using (var stateless = Sfi.OpenStatelessSession()) | ||
{ | ||
var loadedCompany = await (stateless.GetAsync<Company>(companyId)); | ||
|
||
Assert.That(loadedCompany, Is.Not.Null); | ||
Assert.That(loadedCompany.Name, Is.Not.Null); | ||
Assert.That(loadedCompany.Address, Is.Not.Null); | ||
Assert.That(loadedCompany.Address.AddressLine1, Is.Not.Null); | ||
} | ||
} | ||
|
||
[Test] | ||
public async Task StatelessSessionLoadsOneToOneRelatedObject_WithoutPropertyRefAsync() | ||
{ | ||
var companyId = 0; | ||
|
||
using (ISession session = OpenSession()) | ||
{ | ||
using (ITransaction tx = session.BeginTransaction()) | ||
{ | ||
var company = new CompanyO2O { Name = "Test Company" }; | ||
var address = new AddressO2O {AddressLine1 = "Company Address"}; | ||
|
||
address.SetCompany(company); | ||
|
||
// Have to save the address to get the company to be saved as well | ||
// Saving company doesn't save the address. | ||
companyId = (int) await (session.SaveAsync(address)); | ||
|
||
await (tx.CommitAsync()); | ||
} | ||
} | ||
|
||
|
||
using (var stateless = Sfi.OpenStatelessSession()) | ||
{ | ||
var loadedCompany = await (stateless.GetAsync<CompanyO2O>(companyId)); | ||
|
||
Assert.That(loadedCompany, Is.Not.Null); | ||
Assert.That(loadedCompany.Name, Is.Not.Null); | ||
Assert.That(loadedCompany.Address, Is.Not.Null); | ||
Assert.That(loadedCompany.Address.AddressLine1, Is.Not.Null); | ||
} | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
namespace NHibernate.Test.NHSpecificTest.GH1149 | ||
{ | ||
public class Company | ||
{ | ||
public virtual int Id { get; set; } | ||
public virtual string Name { get; set; } | ||
public virtual Address Address { get; set; } | ||
} | ||
|
||
public class Address | ||
{ | ||
public Address() | ||
{ | ||
} | ||
|
||
public Address(Company company) | ||
{ | ||
this.Company = company; | ||
} | ||
|
||
public virtual int Id { get; set; } | ||
|
||
public virtual Company Company { get; set; } | ||
|
||
public virtual string AddressLine1 { get; set; } | ||
|
||
} | ||
|
||
public class CompanyO2O | ||
{ | ||
public virtual int Id { get; set; } | ||
public virtual string Name { get; set; } | ||
public virtual AddressO2O Address { get; set; } | ||
} | ||
|
||
public class AddressO2O | ||
{ | ||
public virtual int Id { get; set; } | ||
|
||
public virtual CompanyO2O Company { get; set; } | ||
|
||
public virtual string AddressLine1 { get; set; } | ||
|
||
public virtual void SetCompany(CompanyO2O company) | ||
{ | ||
Company = company; | ||
company.Address = this; | ||
} | ||
|
||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
using NUnit.Framework; | ||
|
||
namespace NHibernate.Test.NHSpecificTest.GH1149 | ||
{ | ||
[TestFixture] | ||
public class Fixture : BugTestCase | ||
{ | ||
protected override void OnTearDown() | ||
{ | ||
using (ISession session = OpenSession()) | ||
using (ITransaction transaction = session.BeginTransaction()) | ||
{ | ||
session.Delete("from Address"); | ||
session.Delete("from Company"); | ||
session.Delete("from AddressO2O"); | ||
session.Delete("from CompanyO2O"); | ||
session.Flush(); | ||
transaction.Commit(); | ||
} | ||
} | ||
|
||
[Test] | ||
public void StatelessSessionLoadsOneToOneRelatedObject_PropertyRef() | ||
{ | ||
// Create and save company and address | ||
var companyId = 0; | ||
|
||
using (ISession session = OpenSession()) | ||
{ | ||
using (ITransaction tx = session.BeginTransaction()) | ||
{ | ||
var company = new Company { Name = "Test Company" }; | ||
|
||
company.Address = new Address(company) { AddressLine1 = "Company Address" }; | ||
|
||
companyId = (int) session.Save(company); | ||
|
||
tx.Commit(); | ||
} | ||
} | ||
|
||
using (var stateless = Sfi.OpenStatelessSession()) | ||
{ | ||
var loadedCompany = stateless.Get<Company>(companyId); | ||
|
||
Assert.That(loadedCompany, Is.Not.Null); | ||
Assert.That(loadedCompany.Name, Is.Not.Null); | ||
Assert.That(loadedCompany.Address, Is.Not.Null); | ||
Assert.That(loadedCompany.Address.AddressLine1, Is.Not.Null); | ||
} | ||
} | ||
|
||
[Test] | ||
public void StatelessSessionLoadsOneToOneRelatedObject_WithoutPropertyRef() | ||
{ | ||
var companyId = 0; | ||
|
||
using (ISession session = OpenSession()) | ||
{ | ||
using (ITransaction tx = session.BeginTransaction()) | ||
{ | ||
var company = new CompanyO2O { Name = "Test Company" }; | ||
var address = new AddressO2O {AddressLine1 = "Company Address"}; | ||
|
||
address.SetCompany(company); | ||
|
||
// Have to save the address to get the company to be saved as well | ||
// Saving company doesn't save the address. | ||
companyId = (int) session.Save(address); | ||
|
||
tx.Commit(); | ||
} | ||
} | ||
|
||
|
||
using (var stateless = Sfi.OpenStatelessSession()) | ||
{ | ||
var loadedCompany = stateless.Get<CompanyO2O>(companyId); | ||
|
||
Assert.That(loadedCompany, Is.Not.Null); | ||
Assert.That(loadedCompany.Name, Is.Not.Null); | ||
Assert.That(loadedCompany.Address, Is.Not.Null); | ||
Assert.That(loadedCompany.Address.AddressLine1, Is.Not.Null); | ||
} | ||
} | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
src/NHibernate.Test/NHSpecificTest/GH1149/Mappings.hbm.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" | ||
namespace="NHibernate.Test.NHSpecificTest.GH1149" | ||
assembly="NHibernate.Test"> | ||
<class name="Company" > | ||
<id name="Id"> | ||
<generator class="native"/> | ||
</id> | ||
<property name="Name" /> | ||
|
||
<one-to-one name="Address" class="Address" property-ref="Company" cascade="all-delete-orphan"/> | ||
|
||
</class> | ||
|
||
<class name="Address" > | ||
<id name="Id"> | ||
<generator class="native"/> | ||
</id> | ||
<property name="AddressLine1" /> | ||
|
||
<many-to-one name="Company" class="Company" column="CompanyId" unique="true" /> | ||
</class> | ||
|
||
<class name="CompanyO2O" > | ||
<id name="Id"> | ||
<generator class="native"/> | ||
</id> | ||
<property name="Name" /> | ||
|
||
<one-to-one name="Address"/> | ||
|
||
</class> | ||
|
||
<class name="AddressO2O"> | ||
<id name="Id" type="int"> | ||
<generator class="foreign"> | ||
<param name="property">Company</param> | ||
</generator> | ||
</id> | ||
|
||
<property name="AddressLine1" /> | ||
|
||
<one-to-one name="Company" cascade="save-update" constrained="true"/> | ||
</class> | ||
|
||
</hibernate-mapping> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May you add a test with an actual
one-to-one
in db? I mean, aone-to-one
not using aproperty-ref
but with one entity pk being also the pk of the other entity (so a pk which is also a fk), both side mapped asone-to-one
with one side beingconstrained
. (PersonTrueO2O
withAddressTrueO2O
in NH3931 tests is an example of this.)Unless this case is already tested in NHibernate.Test and working (meaning the issue report was not really precise).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, PR updated.