diff --git a/hibernate-core/src/main/java/org/hibernate/query/results/internal/dynamic/DynamicFetchBuilderLegacy.java b/hibernate-core/src/main/java/org/hibernate/query/results/internal/dynamic/DynamicFetchBuilderLegacy.java index fb5fbefbbb..4a8f1e7246 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/results/internal/dynamic/DynamicFetchBuilderLegacy.java +++ b/hibernate-core/src/main/java/org/hibernate/query/results/internal/dynamic/DynamicFetchBuilderLegacy.java @@ -61,6 +61,8 @@ public class DynamicFetchBuilderLegacy private final Map fetchBuilderMap; private final DynamicResultBuilderEntityStandard resultBuilderEntity; + private LockMode lockMode; + public DynamicFetchBuilderLegacy( String tableAlias, String ownerTableAlias, @@ -107,6 +109,7 @@ public class DynamicFetchBuilderLegacy @Override public NativeQuery.FetchReturn setLockMode(LockMode lockMode) { + this.lockMode = lockMode; return this; } @@ -176,6 +179,9 @@ public class DynamicFetchBuilderLegacy final DomainResultCreationStateImpl creationState = impl( domainResultCreationState ); final TableGroup ownerTableGroup = creationState.getFromClauseAccess().findByAlias( ownerTableAlias ); final TableGroup tableGroup; + if ( lockMode != null ) { + domainResultCreationState.getSqlAstCreationState().registerLockMode( tableAlias, lockMode ); + } if ( fetchable instanceof TableGroupJoinProducer ) { final SqlAliasBase sqlAliasBase = new SqlAliasBaseConstant( tableAlias ); final TableGroupJoin tableGroupJoin = ( (TableGroupJoinProducer) fetchable ).createTableGroupJoin( @@ -359,6 +365,7 @@ public class DynamicFetchBuilderLegacy return tableAlias.equals( that.tableAlias ) && ownerTableAlias.equals( that.ownerTableAlias ) && fetchable.equals( that.fetchable ) + && lockMode.equals( that.lockMode ) && Objects.equals( columnNames, that.columnNames ) && Objects.equals( fetchBuilderMap, that.fetchBuilderMap ) && Objects.equals( resultBuilderEntity, that.resultBuilderEntity ); @@ -369,6 +376,7 @@ public class DynamicFetchBuilderLegacy int result = tableAlias.hashCode(); result = 31 * result + ownerTableAlias.hashCode(); result = 31 * result + fetchable.hashCode(); + result = 31 * result + lockMode.hashCode(); result = 31 * result + ( columnNames != null ? columnNames.hashCode() : 0 ); result = 31 * result + ( fetchBuilderMap != null ? fetchBuilderMap.hashCode() : 0 ); result = 31 * result + ( resultBuilderEntity != null ? resultBuilderEntity.hashCode() : 0 );