-
Notifications
You must be signed in to change notification settings - Fork 933
Property-ref on many-to-one with composite id fails #1918
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 4 commits into
nhibernate:master
from
RogerKratz:BidirectionalEmbeddedId
Dec 7, 2018
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
2b4c79f
Loading bidirectional one-to-one with embedded id fails
RogerKratz dfad1b8
Adjust test case
fredericDelaporte caef93e
Fix component SemiResolve failing on already resolved values
fredericDelaporte 17d1e6f
Fix correctly the bug
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
59 changes: 59 additions & 0 deletions
59
src/NHibernate.Test/Async/NHSpecificTest/GH1918/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,59 @@ | ||
//------------------------------------------------------------------------------ | ||
// <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.GH1918 | ||
{ | ||
using System.Threading.Tasks; | ||
[TestFixture] | ||
public class FixtureAsync : BugTestCase | ||
{ | ||
private const string _ingData = "data_ing"; | ||
private readonly EmbId _ingId = new EmbId { X = 5, Y = 6 }; | ||
|
||
protected override void OnSetUp() | ||
{ | ||
var edId = new EmbId { X = 1, Y = 2 }; | ||
var ed = new BiEmbIdRefEdEntity { Id = edId, Data = "data_ed" }; | ||
var ing = new BiEmbIdRefIngEntity { Id = _ingId, Data = _ingData, Reference = ed }; | ||
using (var s = OpenSession()) | ||
using (var tx = s.BeginTransaction()) | ||
{ | ||
s.Save(ed); | ||
s.Save(ing); | ||
tx.Commit(); | ||
} | ||
} | ||
|
||
[Test] | ||
public async Task CanReadBidirectionalEntitiesWithEmbeddedIdAsync() | ||
{ | ||
using (var s = OpenSession()) | ||
using (var tx = s.BeginTransaction()) | ||
{ | ||
var ingEntity = await (s.GetAsync<BiEmbIdRefIngEntity>(_ingId)); | ||
Assert.That(ingEntity.Data, Is.EqualTo(_ingData)); | ||
await (tx.CommitAsync()); | ||
} | ||
} | ||
|
||
protected override void OnTearDown() | ||
{ | ||
using (var session = OpenSession()) | ||
using (var tx = session.BeginTransaction()) | ||
{ | ||
session.CreateQuery("delete from BiEmbIdRefIngEntity").ExecuteUpdate(); | ||
session.CreateQuery("delete from BiEmbIdRefEdEntity").ExecuteUpdate(); | ||
tx.Commit(); | ||
} | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/NHibernate.Test/NHSpecificTest/GH1918/BiEmbIdRefEdEntity.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,22 @@ | ||
namespace NHibernate.Test.NHSpecificTest.GH1918 | ||
{ | ||
public class BiEmbIdRefEdEntity | ||
{ | ||
public virtual EmbId Id { get; set; } | ||
public virtual string Data { get; set; } | ||
public virtual BiEmbIdRefIngEntity Referencing { get; set; } | ||
|
||
public override bool Equals(object obj) | ||
{ | ||
var casted = obj as BiEmbIdRefEdEntity; | ||
if (casted == null) | ||
return false; | ||
return Id.Equals(casted.Id) && Data.Equals(casted.Data); | ||
} | ||
|
||
public override int GetHashCode() | ||
{ | ||
return Id.GetHashCode() ^ Data.GetHashCode(); | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/NHibernate.Test/NHSpecificTest/GH1918/BiEmbIdRefIngEntity.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,22 @@ | ||
namespace NHibernate.Test.NHSpecificTest.GH1918 | ||
{ | ||
public class BiEmbIdRefIngEntity | ||
{ | ||
public virtual EmbId Id { get; set; } | ||
public virtual string Data { get; set; } | ||
public virtual BiEmbIdRefEdEntity Reference { get; set; } | ||
|
||
public override bool Equals(object obj) | ||
{ | ||
var casted = obj as BiEmbIdRefIngEntity; | ||
if (casted == null) | ||
return false; | ||
return Id.Equals(casted.Id) && Data.Equals(casted.Data); | ||
} | ||
|
||
public override int GetHashCode() | ||
{ | ||
return Id.GetHashCode() ^ Data.GetHashCode(); | ||
} | ||
} | ||
} |
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,21 @@ | ||
namespace NHibernate.Test.NHSpecificTest.GH1918 | ||
{ | ||
public class EmbId | ||
{ | ||
public virtual int X { get; set; } | ||
public virtual int Y { get; set; } | ||
|
||
public override bool Equals(object obj) | ||
{ | ||
var casted = obj as EmbId; | ||
if (casted == null) | ||
return false; | ||
return X == casted.X && Y == casted.Y; | ||
} | ||
|
||
public override int GetHashCode() | ||
{ | ||
return X ^ Y; | ||
} | ||
} | ||
} |
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,48 @@ | ||
using NUnit.Framework; | ||
|
||
namespace NHibernate.Test.NHSpecificTest.GH1918 | ||
{ | ||
[TestFixture] | ||
public class Fixture : BugTestCase | ||
{ | ||
private const string _ingData = "data_ing"; | ||
private readonly EmbId _ingId = new EmbId { X = 5, Y = 6 }; | ||
|
||
protected override void OnSetUp() | ||
{ | ||
var edId = new EmbId { X = 1, Y = 2 }; | ||
var ed = new BiEmbIdRefEdEntity { Id = edId, Data = "data_ed" }; | ||
var ing = new BiEmbIdRefIngEntity { Id = _ingId, Data = _ingData, Reference = ed }; | ||
using (var s = OpenSession()) | ||
using (var tx = s.BeginTransaction()) | ||
{ | ||
s.Save(ed); | ||
s.Save(ing); | ||
tx.Commit(); | ||
} | ||
} | ||
|
||
[Test] | ||
public void CanReadBidirectionalEntitiesWithEmbeddedId() | ||
{ | ||
using (var s = OpenSession()) | ||
using (var tx = s.BeginTransaction()) | ||
{ | ||
var ingEntity = s.Get<BiEmbIdRefIngEntity>(_ingId); | ||
Assert.That(ingEntity.Data, Is.EqualTo(_ingData)); | ||
tx.Commit(); | ||
} | ||
} | ||
|
||
protected override void OnTearDown() | ||
{ | ||
using (var session = OpenSession()) | ||
using (var tx = session.BeginTransaction()) | ||
{ | ||
session.CreateQuery("delete from BiEmbIdRefIngEntity").ExecuteUpdate(); | ||
session.CreateQuery("delete from BiEmbIdRefEdEntity").ExecuteUpdate(); | ||
tx.Commit(); | ||
} | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/NHibernate.Test/NHSpecificTest/GH1918/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,28 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" | ||
assembly="NHibernate.Test" | ||
namespace="NHibernate.Test.NHSpecificTest.GH1918"> | ||
|
||
<class name="BiEmbIdRefEdEntity"> | ||
<composite-id name="Id"> | ||
<key-property name="X"/> | ||
<key-property name="Y"/> | ||
</composite-id> | ||
<property name="Data" /> | ||
<one-to-one name="Referencing" | ||
class="BiEmbIdRefIngEntity" | ||
property-ref="Reference"/> | ||
</class> | ||
|
||
<class name="BiEmbIdRefIngEntity"> | ||
<composite-id name="Id"> | ||
<key-property name="X"/> | ||
<key-property name="Y"/> | ||
</composite-id> | ||
<property name="Data" /> | ||
<many-to-one name="Reference"> | ||
<column name="RefX" /> | ||
<column name="RefY" /> | ||
</many-to-one> | ||
</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
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.