Skip to content

Commit 39a6040

Browse files
committed
Fix DML queries
1 parent 9f4d873 commit 39a6040

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

src/NHibernate/Hql/Ast/ANTLR/Tree/FromElement.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -521,18 +521,16 @@ internal string[] GetIdentityColumns()
521521
{
522522
propertyName = NHibernate.Persister.Entity.EntityPersister.EntityID;
523523
}
524-
if (Walker.StatementType == HqlSqlWalker.SELECT || Walker.IsSubQuery)
525-
{
526-
cols = GetPropertyMapping(propertyName).ToColumns(table, propertyName);
527-
}
528-
else
529-
{
530-
cols = GetPropertyMapping(propertyName).ToColumns(propertyName);
531-
}
524+
525+
cols = UseTableAliases
526+
? GetPropertyMapping(propertyName).ToColumns(table, propertyName)
527+
: GetPropertyMapping(propertyName).ToColumns(propertyName);
532528

533529
return cols;
534530
}
535531

532+
internal bool UseTableAliases => Walker.StatementType == HqlSqlWalker.SELECT || Walker.IsSubQuery;
533+
536534
public void HandlePropertyBeingDereferenced(IType propertySource, string propertyName)
537535
{
538536
if (QueryableCollection != null && CollectionProperties.IsCollectionProperty(propertyName))

src/NHibernate/Hql/Ast/ANTLR/Tree/FromElementType.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,12 @@ public JoinSequence JoinSequence
119119
var joinable = _persister as IJoinable;
120120
if (joinable != null)
121121
{
122-
return _fromElement.SessionFactoryHelper.CreateJoinSequence().SetRoot(joinable, TableAlias);
122+
// the delete and update statements created here will never be executed when IsMultiTable is true,
123+
// only the where clause will be used by MultiTableUpdateExecutor/MultiTableDeleteExecutor. In that case
124+
// we have to use the alias from the persister.
125+
var useAlias = _fromElement.UseTableAliases || _fromElement.Queryable.IsMultiTable;
126+
127+
return _fromElement.SessionFactoryHelper.CreateJoinSequence().SetRoot(joinable, useAlias ? TableAlias : string.Empty);
123128
}
124129

125130
return null; // TODO: Should this really return null? If not, figure out something better to do here.

src/NHibernate/Hql/Ast/ANTLR/Util/JoinProcessor.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,6 @@ public void ProcessJoins(QueryNode query)
6666
public void ProcessJoins(IRestrictableStatement query)
6767
{
6868
FromClause fromClause = query.FromClause;
69-
var supportRootAlias = !(query is DeleteStatement || query is UpdateStatement);
70-
7169
IList<FromElement> fromElements;
7270
if ( DotNode.UseThetaStyleImplicitJoins )
7371
{
@@ -118,11 +116,11 @@ public void ProcessJoins(IRestrictableStatement query)
118116
// the delete and update statements created here will never be executed when IsMultiTable is true,
119117
// only the where clause will be used by MultiTableUpdateExecutor/MultiTableDeleteExecutor. In that case
120118
// we have to use the alias from the persister.
121-
AddJoinNodes( query, join, fromElement, supportRootAlias || fromElement.Queryable.IsMultiTable);
119+
AddJoinNodes( query, join, fromElement);
122120
}
123121
}
124122

125-
private void AddJoinNodes(IRestrictableStatement query, JoinSequence join, FromElement fromElement, bool supportRootAlias)
123+
private void AddJoinNodes(IRestrictableStatement query, JoinSequence join, FromElement fromElement)
126124
{
127125
JoinFragment joinFragment = join.ToJoinFragment(
128126
_walker.EnabledFilters,

0 commit comments

Comments
 (0)