-
Notifications
You must be signed in to change notification settings - Fork 934
Fix properties mapped inside a <properties> group are empty when retrieving object #2142
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
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
76 changes: 76 additions & 0 deletions
76
src/NHibernate.Test/Async/NHSpecificTest/NH2714/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,76 @@ | ||
//------------------------------------------------------------------------------ | ||
// <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.NH2714 | ||
{ | ||
using System.Threading.Tasks; | ||
[TestFixture] | ||
public class FixtureAsync : BugTestCase | ||
{ | ||
private const int ExtraId = 500; | ||
|
||
protected override void OnTearDown() | ||
{ | ||
using (ISession s = OpenSession()) | ||
{ | ||
s.Delete($"from {nameof(Item)}"); | ||
s.Flush(); | ||
s.Delete($"from {nameof(Information)}"); | ||
s.Flush(); | ||
} | ||
} | ||
|
||
[Test] | ||
public async Task PropertyRefUsesOtherColumnsAsync() | ||
{ | ||
var information = new Information {Name = "First", ExtraId = ExtraId}; | ||
|
||
var item = new Item {Id = 1, Name = information.Name, ExtraId = information.ExtraId}; | ||
|
||
using (ISession session = OpenSession()) | ||
{ | ||
await (session.SaveAsync(information)); | ||
await (session.SaveAsync(item)); | ||
await (session.FlushAsync()); | ||
} | ||
|
||
using (ISession session = OpenSession()) | ||
{ | ||
var otherInformation = await (session.GetAsync<Information>(information.Id)); | ||
Assert.That(otherInformation.Items.Count, Is.EqualTo(1)); | ||
} | ||
} | ||
|
||
[Test] | ||
public async Task ChildKeyPropertiesOfParentAreRetrievedAsync() | ||
{ | ||
var information = new Information {Name = "First", ExtraId = ExtraId}; | ||
|
||
var item = new Item {Id = 1, Name = information.Name, ExtraId = information.ExtraId}; | ||
|
||
using (ISession session = OpenSession()) | ||
{ | ||
await (session.SaveAsync(information)); | ||
await (session.SaveAsync(item)); | ||
await (session.FlushAsync()); | ||
} | ||
|
||
using (ISession session = OpenSession()) | ||
{ | ||
var otherInformation = await (session.GetAsync<Information>(information.Id)); | ||
|
||
Assert.That(otherInformation.Name, Is.EqualTo(information.Name)); | ||
Assert.That(otherInformation.ExtraId, Is.EqualTo(information.ExtraId)); | ||
} | ||
} | ||
} | ||
} |
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,65 @@ | ||
using NUnit.Framework; | ||
|
||
namespace NHibernate.Test.NHSpecificTest.NH2714 | ||
{ | ||
[TestFixture] | ||
public class Fixture : BugTestCase | ||
{ | ||
private const int ExtraId = 500; | ||
|
||
protected override void OnTearDown() | ||
{ | ||
using (ISession s = OpenSession()) | ||
{ | ||
s.Delete($"from {nameof(Item)}"); | ||
s.Flush(); | ||
s.Delete($"from {nameof(Information)}"); | ||
s.Flush(); | ||
} | ||
} | ||
|
||
[Test] | ||
public void PropertyRefUsesOtherColumns() | ||
{ | ||
var information = new Information {Name = "First", ExtraId = ExtraId}; | ||
|
||
var item = new Item {Id = 1, Name = information.Name, ExtraId = information.ExtraId}; | ||
|
||
using (ISession session = OpenSession()) | ||
{ | ||
session.Save(information); | ||
session.Save(item); | ||
session.Flush(); | ||
} | ||
|
||
using (ISession session = OpenSession()) | ||
{ | ||
var otherInformation = session.Get<Information>(information.Id); | ||
Assert.That(otherInformation.Items.Count, Is.EqualTo(1)); | ||
} | ||
} | ||
|
||
[Test] | ||
public void ChildKeyPropertiesOfParentAreRetrieved() | ||
{ | ||
var information = new Information {Name = "First", ExtraId = ExtraId}; | ||
|
||
var item = new Item {Id = 1, Name = information.Name, ExtraId = information.ExtraId}; | ||
|
||
using (ISession session = OpenSession()) | ||
{ | ||
session.Save(information); | ||
session.Save(item); | ||
session.Flush(); | ||
} | ||
|
||
using (ISession session = OpenSession()) | ||
{ | ||
var otherInformation = session.Get<Information>(information.Id); | ||
|
||
Assert.That(otherInformation.Name, Is.EqualTo(information.Name)); | ||
Assert.That(otherInformation.ExtraId, Is.EqualTo(information.ExtraId)); | ||
} | ||
} | ||
} | ||
} |
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,12 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace NHibernate.Test.NHSpecificTest.NH2714 | ||
{ | ||
public class Information | ||
{ | ||
public virtual int Id { get; set; } | ||
public virtual string Name { get; set; } | ||
public virtual int ExtraId { get; set; } | ||
public virtual ISet<Item> Items { get; set; } = new HashSet<Item>(); | ||
} | ||
} |
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,9 @@ | ||
namespace NHibernate.Test.NHSpecificTest.NH2714 | ||
{ | ||
public class Item | ||
{ | ||
public virtual int Id { get; set; } | ||
public virtual string Name { get; set; } | ||
public virtual int ExtraId { get; set; } | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/NHibernate.Test/NHSpecificTest/NH2714/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,27 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="NHibernate.Test" namespace="NHibernate.Test.NHSpecificTest.NH2714"> | ||
<class name="Information" table="info" lazy="false"> | ||
<id name="Id" column="id"> | ||
<generator class="native" /> | ||
</id> | ||
<properties name="pref"> | ||
<property name="Name" column="aName" /> | ||
<property name="ExtraId" column="aExtraId" /> | ||
</properties> | ||
<set name="Items" lazy="true"> | ||
<key property-ref="pref"> | ||
<column name="aName" /> | ||
<column name="aExtraId" /> | ||
</key> | ||
<one-to-many class="Item" /> | ||
</set> | ||
</class> | ||
|
||
<class name="Item" table="itens"> | ||
<id name="Id" column="id"> | ||
<generator class="assigned" /> | ||
</id> | ||
<property name="Name" column="aName" /> | ||
<property name="ExtraId" column="aExtraId" /> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,9 +19,12 @@ public override bool IsEmbedded | |
|
||
public override object Instantiate(object parent, ISessionImplementor session) | ||
{ | ||
bool useParent= false; | ||
// NH Different implementation : since we are not sure about why H3.2 use the "parent" | ||
//useParent = parent != null && base.ReturnedClass.IsInstanceOfType(parent); | ||
var useParent = | ||
parent != null && | ||
//TODO: Yuck! This is not quite good enough, it's a quick | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
//hack around the problem of having a to-one association | ||
//that refers to an embedded component: | ||
ReturnedClass.IsInstanceOfType(parent); | ||
|
||
return useParent ? parent : base.Instantiate(parent, session); | ||
} | ||
|
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.
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.
So, now we're sure why this code was written like this...