Skip to content

Fix missing alias for subquery entity references in update statements #2218

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 2 commits into from
Sep 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
namespace NHibernate.Test.Hql
{
using System.Threading.Tasks;
using System.Threading;
[TestFixture]
public class AggregateFunctionsWithSubSelectTestAsync : TestCaseMappingByCode
{
Expand Down Expand Up @@ -88,7 +87,7 @@ protected override bool AppliesTo(Dialect.Dialect dialect)
[TestCase("MIN", 2)]
[TestCase("MAX", 2)]
[TestCase("AVG", 2d)]
public async Task TestAggregateFunctionAsync(string functionName, object result, CancellationToken cancellationToken = default(CancellationToken))
public async Task TestAggregateFunctionAsync(string functionName, object result)
{
var query = "SELECT " +
" d.Id, " +
Expand All @@ -107,14 +106,14 @@ protected override bool AppliesTo(Dialect.Dialect dialect)
using (var session = OpenSession())
using (var transaction = session.BeginTransaction())
{
var results = await (session.CreateQuery(query).ListAsync(cancellationToken));
var results = await (session.CreateQuery(query).ListAsync());

Assert.That(results, Has.Count.EqualTo(1));
var tuple = results[0] as object[];
Assert.That(tuple, Is.Not.Null);
Assert.That(tuple, Has.Length.EqualTo(2));
Assert.That(tuple[1], Is.EqualTo(result));
await (transaction.CommitAsync(cancellationToken));
await (transaction.CommitAsync());
}
}
}
Expand Down
62 changes: 62 additions & 0 deletions src/NHibernate.Test/Async/NHSpecificTest/NH2951/Fixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
//------------------------------------------------------------------------------
// <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.Linq;
using NHibernate.Linq;
using NUnit.Framework;

namespace NHibernate.Test.NHSpecificTest.NH2951
{
using System.Threading.Tasks;
[TestFixture]
public class FixtureAsync : BugTestCase
{
protected override void OnTearDown()
{
using (ISession session = OpenSession())
using (ITransaction transaction = session.BeginTransaction())
{
session.Delete("from System.Object");

session.Flush();
transaction.Commit();
}
}

[Test]
public async Task UpdateWithSubqueryToJoinedSubclassAsync()
{
using (ISession session = OpenSession())
using (ITransaction transaction = session.BeginTransaction())
{

var c = new Customer { Name = "Bob" };
await (session.SaveAsync(c));

var i = new Invoice { Amount = 10 };
await (session.SaveAsync(i));

await (session.FlushAsync());
await (transaction.CommitAsync());
}

using (ISession session = OpenSession())
using (session.BeginTransaction())
{
// Using (select c.Id ...) works.
string hql = "update Invoice i set i.Customer = (select c from Customer c where c.Name = 'Bob')";

int result = await (session.CreateQuery(hql).ExecuteUpdateAsync());

Assert.AreEqual(1, result);
}
}
}
}
2 changes: 1 addition & 1 deletion src/NHibernate.Test/Async/NHSpecificTest/NH750/Fixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public async Task DeviceOfDriveAsync()
await (t.CommitAsync());
}

await (VerifyResultAsync(2,2, msg: "modified collection"));
await (VerifyResultAsync(2, 2, msg: "modified collection"));

async Task VerifyResultAsync(int expectedInCollection, int expectedInDb, string msg)
{
Expand Down
3 changes: 1 addition & 2 deletions src/NHibernate.Test/NHSpecificTest/NH2951/Fixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ protected override void OnTearDown()
}

[Test]
[Ignore("Not working.")]
public void UpdateWithSubqueryToJoinedSubclass()
{
using (ISession session = OpenSession())
Expand Down Expand Up @@ -49,4 +48,4 @@ public void UpdateWithSubqueryToJoinedSubclass()
}
}
}
}
}
2 changes: 1 addition & 1 deletion src/NHibernate/Hql/Ast/ANTLR/Tree/FromElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ public virtual string GetIdentityColumn()
{
propertyName = NHibernate.Persister.Entity.EntityPersister.EntityID;
}
if (Walker.StatementType == HqlSqlWalker.SELECT)
if (Walker.StatementType == HqlSqlWalker.SELECT || Walker.IsSubQuery)
{
cols = GetPropertyMapping(propertyName).ToColumns(table, propertyName);
}
Expand Down