-
Notifications
You must be signed in to change notification settings - Fork 934
Fixes #3334 #3335
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
Closed
Closed
Fixes #3334 #3335
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
112 changes: 112 additions & 0 deletions
112
src/NHibernate.Test/Async/NHSpecificTest/GH3334/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,112 @@ | ||
//------------------------------------------------------------------------------ | ||
// <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.GH3334 | ||
{ | ||
using System.Threading.Tasks; | ||
[TestFixture] | ||
public class FixtureAsync : BugTestCase | ||
{ | ||
protected override void OnSetUp() | ||
{ | ||
Sfi.Statistics.IsStatisticsEnabled = true; | ||
} | ||
|
||
protected override void OnTearDown() | ||
{ | ||
Sfi.Statistics.IsStatisticsEnabled = false; | ||
using (var session = OpenSession()) | ||
using (var transaction = session.BeginTransaction()) | ||
{ | ||
session.CreateQuery("delete from ChildEntity").ExecuteUpdate(); | ||
session.CreateQuery("delete from GrandChildEntity").ExecuteUpdate(); | ||
session.CreateQuery("delete from Entity").ExecuteUpdate(); | ||
session.CreateQuery("delete from OtherEntity").ExecuteUpdate(); | ||
|
||
transaction.Commit(); | ||
} | ||
} | ||
|
||
[Test] | ||
public async Task NoExceptionOnExecuteQueryAsync() | ||
{ | ||
using (var session = OpenSession()) | ||
using (var t = session.BeginTransaction()) | ||
{ | ||
var parent = new Entity | ||
{ | ||
Name = "Parent1", | ||
Children = { new ChildEntity { Name = "Child", Child = new GrandChildEntity { Name = "GrandChild" } } } | ||
}; | ||
await (session.SaveAsync(parent)); | ||
parent = new Entity | ||
{ | ||
Name = "Parent2", | ||
Children = { new ChildEntity { Name = "Child", Child = new GrandChildEntity { Name = "XGrandChild" } } } | ||
}; | ||
var other = new OtherEntity { Name = "ABC", Entities = {parent}}; | ||
parent.OtherEntity = other; | ||
await (session.SaveAsync(parent)); | ||
await (session.SaveAsync(other)); | ||
await (t.CommitAsync()); | ||
} | ||
|
||
using (var session = OpenSession()) | ||
using (var _ = session.BeginTransaction()) | ||
{ | ||
var q = session.CreateQuery( | ||
@" | ||
SELECT ROOT | ||
FROM Entity AS ROOT | ||
WHERE | ||
EXISTS | ||
(FROM ELEMENTS(ROOT.Children) AS child | ||
LEFT JOIN child.Child AS grandChild | ||
LEFT JOIN ROOT.OtherEntity AS otherEntity | ||
WHERE | ||
grandChild.Name like 'G%' | ||
OR otherEntity.Name like 'G%' | ||
)"); | ||
Assert.AreEqual(1, (await (q.ListAsync())).Count); | ||
|
||
q = session.CreateQuery( | ||
@" | ||
SELECT ROOT | ||
FROM Entity AS ROOT | ||
WHERE | ||
EXISTS | ||
(FROM ELEMENTS(ROOT.Children) AS child | ||
LEFT JOIN child.Child AS grandChild | ||
LEFT JOIN ROOT.OtherEntity AS otherEntity | ||
WHERE | ||
grandChild.Name like 'A%' | ||
OR otherEntity.Name like 'A%' | ||
)"); | ||
Assert.AreEqual(1, (await (q.ListAsync())).Count); | ||
|
||
/* does not work because of inner join or theta join created for many-to-one | ||
q = session.CreateQuery( | ||
@" | ||
SELECT ROOT | ||
FROM Entity AS ROOT | ||
WHERE | ||
EXISTS | ||
(FROM ELEMENTS(ROOT.Children) AS child | ||
WHERE | ||
child.Child.Name like 'G%' | ||
OR ROOT.OtherEntity.Name like 'A%' | ||
)"); | ||
Assert.AreEqual(1, q.List().Count);*/ | ||
} | ||
} | ||
} | ||
} |
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,32 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace NHibernate.Test.NHSpecificTest.GH3334 | ||
{ | ||
public class Entity | ||
{ | ||
public virtual int Id { get; set; } | ||
public virtual string Name { get; set; } | ||
public virtual ISet<ChildEntity> Children { get; set; } = new HashSet<ChildEntity>(); | ||
public virtual OtherEntity OtherEntity { get; set; } | ||
} | ||
|
||
public class ChildEntity | ||
{ | ||
public virtual int Id { get; set; } | ||
public virtual string Name { get; set; } | ||
public virtual GrandChildEntity Child { get; set; } | ||
} | ||
|
||
public class GrandChildEntity | ||
{ | ||
public virtual int Id { get; set; } | ||
public virtual string Name { get; set; } | ||
} | ||
|
||
public class OtherEntity | ||
{ | ||
public virtual int Id { get; set; } | ||
public virtual string Name { get; set; } | ||
public virtual ISet<Entity> Entities { get; set; } = new HashSet<Entity>(); | ||
} | ||
} |
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,101 @@ | ||
using NUnit.Framework; | ||
|
||
namespace NHibernate.Test.NHSpecificTest.GH3334 | ||
{ | ||
[TestFixture] | ||
public class Fixture : BugTestCase | ||
{ | ||
protected override void OnSetUp() | ||
{ | ||
Sfi.Statistics.IsStatisticsEnabled = true; | ||
} | ||
|
||
protected override void OnTearDown() | ||
{ | ||
Sfi.Statistics.IsStatisticsEnabled = false; | ||
using (var session = OpenSession()) | ||
using (var transaction = session.BeginTransaction()) | ||
{ | ||
session.CreateQuery("delete from ChildEntity").ExecuteUpdate(); | ||
session.CreateQuery("delete from GrandChildEntity").ExecuteUpdate(); | ||
session.CreateQuery("delete from Entity").ExecuteUpdate(); | ||
session.CreateQuery("delete from OtherEntity").ExecuteUpdate(); | ||
|
||
transaction.Commit(); | ||
} | ||
} | ||
|
||
[Test] | ||
public void NoExceptionOnExecuteQuery() | ||
{ | ||
using (var session = OpenSession()) | ||
using (var t = session.BeginTransaction()) | ||
{ | ||
var parent = new Entity | ||
{ | ||
Name = "Parent1", | ||
Children = { new ChildEntity { Name = "Child", Child = new GrandChildEntity { Name = "GrandChild" } } } | ||
}; | ||
session.Save(parent); | ||
parent = new Entity | ||
{ | ||
Name = "Parent2", | ||
Children = { new ChildEntity { Name = "Child", Child = new GrandChildEntity { Name = "XGrandChild" } } } | ||
}; | ||
var other = new OtherEntity { Name = "ABC", Entities = {parent}}; | ||
parent.OtherEntity = other; | ||
session.Save(parent); | ||
session.Save(other); | ||
t.Commit(); | ||
} | ||
|
||
using (var session = OpenSession()) | ||
using (var _ = session.BeginTransaction()) | ||
{ | ||
var q = session.CreateQuery( | ||
@" | ||
SELECT ROOT | ||
FROM Entity AS ROOT | ||
WHERE | ||
EXISTS | ||
(FROM ELEMENTS(ROOT.Children) AS child | ||
LEFT JOIN child.Child AS grandChild | ||
LEFT JOIN ROOT.OtherEntity AS otherEntity | ||
WHERE | ||
grandChild.Name like 'G%' | ||
OR otherEntity.Name like 'G%' | ||
)"); | ||
Assert.AreEqual(1, q.List().Count); | ||
|
||
q = session.CreateQuery( | ||
@" | ||
SELECT ROOT | ||
FROM Entity AS ROOT | ||
WHERE | ||
EXISTS | ||
(FROM ELEMENTS(ROOT.Children) AS child | ||
LEFT JOIN child.Child AS grandChild | ||
LEFT JOIN ROOT.OtherEntity AS otherEntity | ||
WHERE | ||
grandChild.Name like 'A%' | ||
OR otherEntity.Name like 'A%' | ||
)"); | ||
Assert.AreEqual(1, q.List().Count); | ||
|
||
/* does not work because of inner join or theta join created for many-to-one | ||
q = session.CreateQuery( | ||
@" | ||
SELECT ROOT | ||
FROM Entity AS ROOT | ||
WHERE | ||
EXISTS | ||
(FROM ELEMENTS(ROOT.Children) AS child | ||
WHERE | ||
child.Child.Name like 'G%' | ||
OR ROOT.OtherEntity.Name like 'A%' | ||
)"); | ||
Assert.AreEqual(1, q.List().Count);*/ | ||
} | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/NHibernate.Test/NHSpecificTest/GH3334/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.GH3334"> | ||
|
||
<class name="Entity"> | ||
<id name="Id" generator="identity" /> | ||
<property name="Name"/> | ||
<set name="Children" cascade="persist,delete,save-update,evict,lock,replicate,delete-orphan"> | ||
<key column="Parent" /> | ||
<one-to-many class="ChildEntity"/> | ||
</set> | ||
<many-to-one name="OtherEntity" class="OtherEntity"/> | ||
</class> | ||
|
||
<class name="ChildEntity"> | ||
<id name="Id" generator="identity" /> | ||
<property name="Name"/> | ||
<many-to-one name="Child" class="GrandChildEntity" cascade="persist,delete,save-update,evict,lock,replicate,delete-orphan"/> | ||
</class> | ||
|
||
<class name="GrandChildEntity"> | ||
<id name="Id" generator="identity" /> | ||
<property name="Name"/> | ||
</class> | ||
|
||
<class name="OtherEntity"> | ||
<id name="Id" generator="identity" /> | ||
<property name="Name"/> | ||
<set name="Entities" inverse="true" lazy="true"> | ||
<key column="OtherEntity" /> | ||
<one-to-many class="Entity" /> | ||
</set> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -283,13 +283,13 @@ public FromElement CreateElementJoin(IQueryableCollection queryableCollection) | |
return elem; | ||
} | ||
|
||
public FromElement CreateEntityJoin( | ||
string entityClass, | ||
string tableAlias, | ||
JoinSequence joinSequence, | ||
bool fetchFlag, | ||
bool inFrom, | ||
EntityType type) | ||
public FromElement CreateEntityJoin(string entityClass, | ||
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. This would require a method overload |
||
string tableAlias, | ||
JoinSequence joinSequence, | ||
JoinType joinType, | ||
bool fetchFlag, | ||
bool inFrom, | ||
EntityType type) | ||
{ | ||
FromElement elem = CreateJoin(entityClass, tableAlias, joinSequence, type, false); | ||
elem.Fetch = fetchFlag; | ||
|
@@ -315,7 +315,7 @@ public FromElement CreateEntityJoin( | |
elem.UseFromFragment = true; | ||
elem.SetImpliedInFromClause(true); | ||
} | ||
if (elem.Walker.IsSubQuery) | ||
if (elem.Walker.IsSubQuery && joinType != JoinType.LeftOuterJoin && joinType != JoinType.RightOuterJoin && joinType != JoinType.FullJoin) | ||
{ | ||
// two conditions where we need to transform this to a theta-join syntax: | ||
// 1) 'elem' is the "root from-element" in correlated subqueries | ||
|
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.
nit: whitespace