-
Notifications
You must be signed in to change notification settings - Fork 936
Fix filtering sub-queries on property-ref #3685
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
Open
fredericDelaporte
wants to merge
3
commits into
nhibernate:5.4.x
Choose a base branch
from
fredericDelaporte:GH3609
base: 5.4.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 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
114 changes: 114 additions & 0 deletions
114
src/NHibernate.Test/Async/NHSpecificTest/GH3609/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,114 @@ | ||
//------------------------------------------------------------------------------ | ||
// <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 System; | ||
using System.Linq; | ||
using NUnit.Framework; | ||
using NHibernate.Linq; | ||
|
||
namespace NHibernate.Test.NHSpecificTest.GH3609 | ||
{ | ||
using System.Threading.Tasks; | ||
[TestFixture] | ||
public class FixtureAsync : BugTestCase | ||
{ | ||
protected override void OnSetUp() | ||
{ | ||
using var session = OpenSession(); | ||
using var transaction = session.BeginTransaction(); | ||
|
||
var order = new Order | ||
{ | ||
UniqueId = "0ab92479-8a17-4dbc-9bef-ce4344940cec", | ||
CreatedDate = new DateTime(2024, 09, 24) | ||
}; | ||
session.Save(order); | ||
session.Save(new LineItem { Order = order, ItemName = "Bananas", Amount = 5 }); | ||
session.Save(new CleanLineItem { Order = order, ItemName = "Bananas", Amount = 5 }); | ||
|
||
order = new Order | ||
{ | ||
UniqueId = "4ca17d84-97aa-489f-8701-302a3879a388", | ||
CreatedDate = new DateTime(2021, 09, 19) | ||
}; | ||
session.Save(order); | ||
session.Save(new LineItem { Order = order, ItemName = "Apples", Amount = 10 }); | ||
session.Save(new CleanLineItem { Order = order, ItemName = "Apples", Amount = 10 }); | ||
|
||
transaction.Commit(); | ||
} | ||
|
||
protected override void OnTearDown() | ||
{ | ||
using var session = OpenSession(); | ||
using var transaction = session.BeginTransaction(); | ||
|
||
session.CreateQuery("delete from CleanLineItem").ExecuteUpdate(); | ||
session.CreateQuery("delete from System.Object").ExecuteUpdate(); | ||
|
||
transaction.Commit(); | ||
} | ||
|
||
[Test] | ||
public async Task QueryWithAnyAsync() | ||
{ | ||
using var session = OpenSession(); | ||
using var transaction = session.BeginTransaction(); | ||
|
||
// This form of query is how we first discovered the issue. This is a simplified reproduction of the | ||
// sort of Linq that we were using in our app. It seems to occur when we force an EXISTS( ... ) subquery. | ||
var validOrders = session.Query<Order>().Where(x => x.CreatedDate > new DateTime(2024, 9, 10)); | ||
var orderCount = await (session.Query<LineItem>().CountAsync(x => validOrders.Any(y => y == x.Order))); | ||
|
||
Assert.That(orderCount, Is.EqualTo(1)); | ||
await (transaction.CommitAsync()); | ||
} | ||
|
||
[Test] | ||
public async Task QueryWithAnyOnCleanLinesAsync() | ||
{ | ||
using var session = OpenSession(); | ||
using var transaction = session.BeginTransaction(); | ||
|
||
// This form of query is how we first discovered the issue. This is a simplified reproduction of the | ||
// sort of Linq that we were using in our app. It seems to occur when we force an EXISTS( ... ) subquery. | ||
var validOrders = session.Query<Order>().Where(x => x.CreatedDate > new DateTime(2024, 9, 10)); | ||
var orderCount = await (session.Query<CleanLineItem>().CountAsync(x => validOrders.Any(y => y == x.Order))); | ||
|
||
Assert.That(orderCount, Is.EqualTo(1)); | ||
await (transaction.CommitAsync()); | ||
} | ||
|
||
[Test] | ||
public async Task QueryWithContainsAsync() | ||
{ | ||
using var session = OpenSession(); | ||
using var transaction = session.BeginTransaction(); | ||
|
||
var validOrders = session.Query<Order>().Where(x => x.CreatedDate > new DateTime(2024, 9, 10)); | ||
var orderCount = await (session.Query<LineItem>().CountAsync(x => validOrders.Contains(x.Order))); | ||
|
||
Assert.That(orderCount, Is.EqualTo(1)); | ||
await (transaction.CommitAsync()); | ||
} | ||
|
||
[Test] | ||
public async Task SimpleQueryForDataWhichWasInsertedViaAdoShouldProvideExpectedResultsAsync() | ||
{ | ||
using var session = OpenSession(); | ||
using var transaction = session.BeginTransaction(); | ||
|
||
// This style of equivalent query does not exhibit the problem. This test passes no matter which NH version. | ||
var lineItem = await (session.Query<LineItem>().FirstOrDefaultAsync(x => x.Order.CreatedDate > new DateTime(2024, 9, 10))); | ||
Assert.That(lineItem, Is.Not.Null); | ||
await (transaction.CommitAsync()); | ||
} | ||
} | ||
} |
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 @@ | ||
using System; | ||
|
||
namespace NHibernate.Test.NHSpecificTest.GH3609 | ||
{ | ||
public class Order | ||
{ | ||
public virtual long Id { get; set; } | ||
|
||
public virtual string UniqueId { get; set; } = Guid.NewGuid().ToString(); | ||
|
||
public virtual DateTime CreatedDate { get; set; } | ||
} | ||
|
||
public class LineItem | ||
{ | ||
public virtual long Id { get; set; } | ||
|
||
public virtual Order Order { get; set; } | ||
|
||
public virtual string ItemName { get; set; } | ||
|
||
public virtual decimal Amount { get; set; } | ||
} | ||
|
||
public class CleanLineItem | ||
{ | ||
public virtual long Id { get; set; } | ||
|
||
public virtual Order Order { get; set; } | ||
|
||
public virtual string ItemName { get; set; } | ||
|
||
public virtual decimal Amount { 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,102 @@ | ||
using System; | ||
using System.Linq; | ||
using NUnit.Framework; | ||
|
||
namespace NHibernate.Test.NHSpecificTest.GH3609 | ||
{ | ||
[TestFixture] | ||
public class Fixture : BugTestCase | ||
{ | ||
protected override void OnSetUp() | ||
{ | ||
using var session = OpenSession(); | ||
using var transaction = session.BeginTransaction(); | ||
|
||
var order = new Order | ||
{ | ||
UniqueId = "0ab92479-8a17-4dbc-9bef-ce4344940cec", | ||
CreatedDate = new DateTime(2024, 09, 24) | ||
}; | ||
session.Save(order); | ||
session.Save(new LineItem { Order = order, ItemName = "Bananas", Amount = 5 }); | ||
session.Save(new CleanLineItem { Order = order, ItemName = "Bananas", Amount = 5 }); | ||
|
||
order = new Order | ||
{ | ||
UniqueId = "4ca17d84-97aa-489f-8701-302a3879a388", | ||
CreatedDate = new DateTime(2021, 09, 19) | ||
}; | ||
session.Save(order); | ||
session.Save(new LineItem { Order = order, ItemName = "Apples", Amount = 10 }); | ||
session.Save(new CleanLineItem { Order = order, ItemName = "Apples", Amount = 10 }); | ||
|
||
transaction.Commit(); | ||
} | ||
|
||
protected override void OnTearDown() | ||
{ | ||
using var session = OpenSession(); | ||
using var transaction = session.BeginTransaction(); | ||
|
||
session.CreateQuery("delete from CleanLineItem").ExecuteUpdate(); | ||
session.CreateQuery("delete from System.Object").ExecuteUpdate(); | ||
|
||
transaction.Commit(); | ||
} | ||
|
||
[Test] | ||
public void QueryWithAny() | ||
{ | ||
using var session = OpenSession(); | ||
using var transaction = session.BeginTransaction(); | ||
|
||
// This form of query is how we first discovered the issue. This is a simplified reproduction of the | ||
// sort of Linq that we were using in our app. It seems to occur when we force an EXISTS( ... ) subquery. | ||
var validOrders = session.Query<Order>().Where(x => x.CreatedDate > new DateTime(2024, 9, 10)); | ||
var orderCount = session.Query<LineItem>().Count(x => validOrders.Any(y => y == x.Order)); | ||
|
||
Assert.That(orderCount, Is.EqualTo(1)); | ||
transaction.Commit(); | ||
} | ||
|
||
[Test] | ||
public void QueryWithAnyOnCleanLines() | ||
{ | ||
using var session = OpenSession(); | ||
using var transaction = session.BeginTransaction(); | ||
|
||
// This form of query is how we first discovered the issue. This is a simplified reproduction of the | ||
// sort of Linq that we were using in our app. It seems to occur when we force an EXISTS( ... ) subquery. | ||
var validOrders = session.Query<Order>().Where(x => x.CreatedDate > new DateTime(2024, 9, 10)); | ||
var orderCount = session.Query<CleanLineItem>().Count(x => validOrders.Any(y => y == x.Order)); | ||
|
||
Assert.That(orderCount, Is.EqualTo(1)); | ||
transaction.Commit(); | ||
} | ||
|
||
[Test] | ||
public void QueryWithContains() | ||
{ | ||
using var session = OpenSession(); | ||
using var transaction = session.BeginTransaction(); | ||
|
||
var validOrders = session.Query<Order>().Where(x => x.CreatedDate > new DateTime(2024, 9, 10)); | ||
var orderCount = session.Query<LineItem>().Count(x => validOrders.Contains(x.Order)); | ||
|
||
Assert.That(orderCount, Is.EqualTo(1)); | ||
transaction.Commit(); | ||
} | ||
|
||
[Test] | ||
public void SimpleQueryForDataWhichWasInsertedViaAdoShouldProvideExpectedResults() | ||
{ | ||
using var session = OpenSession(); | ||
using var transaction = session.BeginTransaction(); | ||
|
||
// This style of equivalent query does not exhibit the problem. This test passes no matter which NH version. | ||
var lineItem = session.Query<LineItem>().FirstOrDefault(x => x.Order.CreatedDate > new DateTime(2024, 9, 10)); | ||
Assert.That(lineItem, Is.Not.Null); | ||
transaction.Commit(); | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/NHibernate.Test/NHSpecificTest/GH3609/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,30 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="NHibernate.Test" | ||
namespace="NHibernate.Test.NHSpecificTest.GH3609"> | ||
|
||
<class name="Order" table="TheOrder"> | ||
<id name="Id" generator="identity" /> | ||
<property name="CreatedDate" /> | ||
<property name="UniqueId" unique="true" /> | ||
</class> | ||
|
||
<class name="LineItem"> | ||
<id name="Id" generator="identity" /> | ||
<property name="ItemName" /> | ||
<property name="Amount" /> | ||
<many-to-one name="Order" | ||
property-ref="UniqueId" | ||
not-found="ignore" | ||
column="OrderId" /> | ||
</class> | ||
|
||
<class name="CleanLineItem"> | ||
<id name="Id" generator="identity" /> | ||
<property name="ItemName" /> | ||
<property name="Amount" /> | ||
<many-to-one name="Order" | ||
property-ref="UniqueId" | ||
column="OrderId" /> | ||
</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
Oops, something went wrong.
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.
This fixes NH-892 regression.