-
Notifications
You must be signed in to change notification settings - Fork 933
Fix property-ref on a component's property #1871
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 2 commits into
nhibernate:master
from
fredericDelaporte:propertyRefOnComponentProperty
Oct 15, 2018
Merged
Changes from all commits
Commits
Show all changes
2 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
98 changes: 98 additions & 0 deletions
98
src/NHibernate.Test/Async/NHSpecificTest/GH1824/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.GH1824 | ||
{ | ||
using System.Threading.Tasks; | ||
[TestFixture] | ||
public class FixtureAsync : BugTestCase | ||
{ | ||
private object _fooId; | ||
private object _barId; | ||
|
||
protected override void OnSetUp() | ||
{ | ||
using (var session = OpenSession()) | ||
using (var transaction = session.BeginTransaction()) | ||
{ | ||
var bar = new Bar | ||
{ | ||
MyProps = | ||
{ | ||
["DynValString2"] = "a" | ||
}, | ||
StaticProps = new StaticBarComponent | ||
{ | ||
StaticValString2 = "b" | ||
} | ||
}; | ||
_barId = session.Save(bar); | ||
_fooId = session.Save( | ||
new Foo | ||
{ | ||
MyProps = | ||
{ | ||
["DynPointer"] = bar | ||
}, | ||
StaticProps = new StaticFooComponent | ||
{ | ||
StaticPointer = bar | ||
} | ||
}); | ||
transaction.Commit(); | ||
} | ||
} | ||
|
||
protected override void OnTearDown() | ||
{ | ||
using (var session = OpenSession()) | ||
using (var transaction = session.BeginTransaction()) | ||
{ | ||
// The HQL delete does all the job inside the database without loading the entities, but it does | ||
// not handle delete order for avoiding violating constraints if any. Use | ||
// session.Delete("from System.Object"); | ||
// instead if in need of having NHbernate ordering the deletes, but this will cause | ||
// loading the entities in the session. | ||
session.CreateQuery("delete from System.Object").ExecuteUpdate(); | ||
|
||
transaction.Commit(); | ||
} | ||
} | ||
|
||
[Test] | ||
public async Task CanReadDynPointerFromFooAsync() | ||
{ | ||
using (var session = OpenSession()) | ||
using (session.BeginTransaction()) | ||
{ | ||
var foo = await (session.GetAsync<Foo>(_fooId)); | ||
var bar = foo.MyProps["DynPointer"]; | ||
Assert.That(bar, Is.Not.Null); | ||
Assert.That(bar, Is.InstanceOf<Bar>()); | ||
Assert.That(bar, Has.Property("Id").EqualTo(_barId)); | ||
} | ||
} | ||
|
||
[Test] | ||
public async Task CanReadStaticPointerFromFooAsync() | ||
{ | ||
using (var session = OpenSession()) | ||
using (session.BeginTransaction()) | ||
{ | ||
var foo = await (session.GetAsync<Foo>(_fooId)); | ||
var bar = foo.StaticProps.StaticPointer; | ||
Assert.That(bar, Is.Not.Null); | ||
Assert.That(bar, Has.Property("Id").EqualTo(_barId)); | ||
} | ||
} | ||
} | ||
} |
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,20 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
|
||
namespace NHibernate.Test.NHSpecificTest.GH1824 | ||
{ | ||
public class Bar | ||
{ | ||
public virtual int Id { get; set; } | ||
|
||
public virtual IDictionary MyProps { get; set; } = new Dictionary<string, object>(); | ||
|
||
public virtual StaticBarComponent StaticProps { get; set; } | ||
} | ||
|
||
public class StaticBarComponent | ||
{ | ||
public string StaticValString2 { get; set; } | ||
public string YetAnotherProperty { get; set; } | ||
} | ||
} |
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.GH1824 | ||
{ | ||
[TestFixture] | ||
public class Fixture : BugTestCase | ||
{ | ||
private object _fooId; | ||
private object _barId; | ||
|
||
protected override void OnSetUp() | ||
{ | ||
using (var session = OpenSession()) | ||
using (var transaction = session.BeginTransaction()) | ||
{ | ||
var bar = new Bar | ||
{ | ||
MyProps = | ||
{ | ||
["DynValString2"] = "a" | ||
}, | ||
StaticProps = new StaticBarComponent | ||
{ | ||
StaticValString2 = "b" | ||
} | ||
}; | ||
_barId = session.Save(bar); | ||
_fooId = session.Save( | ||
new Foo | ||
{ | ||
MyProps = | ||
{ | ||
["DynPointer"] = bar | ||
}, | ||
StaticProps = new StaticFooComponent | ||
{ | ||
StaticPointer = bar | ||
} | ||
}); | ||
transaction.Commit(); | ||
} | ||
} | ||
|
||
protected override void OnTearDown() | ||
{ | ||
using (var session = OpenSession()) | ||
using (var transaction = session.BeginTransaction()) | ||
{ | ||
// The HQL delete does all the job inside the database without loading the entities, but it does | ||
// not handle delete order for avoiding violating constraints if any. Use | ||
// session.Delete("from System.Object"); | ||
// instead if in need of having NHbernate ordering the deletes, but this will cause | ||
// loading the entities in the session. | ||
session.CreateQuery("delete from System.Object").ExecuteUpdate(); | ||
|
||
transaction.Commit(); | ||
} | ||
} | ||
|
||
[Test] | ||
public void CanReadDynPointerFromFoo() | ||
{ | ||
using (var session = OpenSession()) | ||
using (session.BeginTransaction()) | ||
{ | ||
var foo = session.Get<Foo>(_fooId); | ||
var bar = foo.MyProps["DynPointer"]; | ||
Assert.That(bar, Is.Not.Null); | ||
Assert.That(bar, Is.InstanceOf<Bar>()); | ||
Assert.That(bar, Has.Property("Id").EqualTo(_barId)); | ||
} | ||
} | ||
|
||
[Test] | ||
public void CanReadStaticPointerFromFoo() | ||
{ | ||
using (var session = OpenSession()) | ||
using (session.BeginTransaction()) | ||
{ | ||
var foo = session.Get<Foo>(_fooId); | ||
var bar = foo.StaticProps.StaticPointer; | ||
Assert.That(bar, Is.Not.Null); | ||
Assert.That(bar, Has.Property("Id").EqualTo(_barId)); | ||
} | ||
} | ||
} | ||
} |
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,19 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
|
||
namespace NHibernate.Test.NHSpecificTest.GH1824 | ||
{ | ||
public class Foo | ||
{ | ||
public virtual int Id { get; set; } | ||
|
||
public virtual IDictionary MyProps { get; set; } = new Dictionary<string, object>(); | ||
|
||
public virtual StaticFooComponent StaticProps { get; set; } | ||
} | ||
|
||
public class StaticFooComponent | ||
{ | ||
public Bar StaticPointer { get; set; } | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/NHibernate.Test/NHSpecificTest/GH1824/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,35 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" | ||
assembly="NHibernate.Test" | ||
namespace="NHibernate.Test.NHSpecificTest.GH1824"> | ||
|
||
<class name="Foo"> | ||
<id type="int" name="Id"> | ||
<column name="Id"/> | ||
<generator class="native"/> | ||
</id> | ||
|
||
<dynamic-component name="MyProps"> | ||
<many-to-one name="DynPointer" class="Bar" property-ref="MyProps.DynValString2"/> | ||
</dynamic-component> | ||
|
||
<component name="StaticProps"> | ||
<many-to-one name="StaticPointer" class="Bar" property-ref="StaticProps.StaticValString2"/> | ||
</component> | ||
</class> | ||
|
||
<class name="Bar"> | ||
<id type="int" name="Id"> | ||
<column name="Id"/> | ||
<generator class="native"/> | ||
</id> | ||
<dynamic-component name="MyProps"> | ||
<property name="DynValString2" type="string" unique="1"/> | ||
<property name="AnotherProperty" type="string" /> | ||
</dynamic-component> | ||
<component name="StaticProps"> | ||
<property name="StaticValString2" type="string" unique="1"/> | ||
<property name="YetAnotherProperty" type="string" /> | ||
</component> | ||
</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.
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.
GetProperty
yields properties of the entity, it does not go inside components for yielding the component property.