Skip to content

Commit

Permalink
HHH-18992 - fix for issue (addition to fix provided in #9517)
Browse files Browse the repository at this point in the history
Signed-off-by: Jan Schatteman <jschatte@redhat.com>
  • Loading branch information
jrenaat committed Feb 6, 2025
1 parent 7292aac commit ca1d66f
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,42 @@
*/
package org.hibernate.loader.ast.internal;

import org.hibernate.LockOptions;
import org.hibernate.engine.spi.EntityHolder;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.engine.spi.SubselectFetch;
import org.hibernate.query.internal.SimpleQueryOptions;
import org.hibernate.query.spi.QueryOptions;
import org.hibernate.sql.exec.internal.BaseExecutionContext;

class ExecutionContextWithSubselectFetchHandler extends BaseExecutionContext {

private final SubselectFetch.RegistrationHandler subSelectFetchableKeysHandler;
private final boolean readOnly;
private final QueryOptions queryOptions;

public ExecutionContextWithSubselectFetchHandler(
SharedSessionContractImplementor session,
SubselectFetch.RegistrationHandler subSelectFetchableKeysHandler) {
this( session, subSelectFetchableKeysHandler, false );
super( session );
this.subSelectFetchableKeysHandler = subSelectFetchableKeysHandler;
this.readOnly = false;
this.queryOptions = QueryOptions.NONE;
}

public ExecutionContextWithSubselectFetchHandler(
SharedSessionContractImplementor session,
SubselectFetch.RegistrationHandler subSelectFetchableKeysHandler,
boolean readOnly) {
boolean readOnly,
LockOptions lockOptions) {
super( session );
this.subSelectFetchableKeysHandler = subSelectFetchableKeysHandler;
this.readOnly = readOnly;
this.queryOptions = determineQueryOptions( readOnly, lockOptions );
}

private QueryOptions determineQueryOptions(boolean readOnly, LockOptions lockOptions) {
return new SimpleQueryOptions( lockOptions, readOnly ? true : null );
}

@Override
Expand All @@ -39,6 +51,11 @@ public void registerLoadingEntityHolder(EntityHolder holder) {

@Override
public QueryOptions getQueryOptions() {
return readOnly ? QueryOptions.READ_ONLY : super.getQueryOptions();
return queryOptions;
}

@Override
public boolean upgradeLocks() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ public LockOptions getLockOptions() {
JdbcParametersList.singleton( jdbcParameter ),
jdbcParameterBindings
),
TRUE.equals( loadOptions.getReadOnly( session ) )
TRUE.equals( loadOptions.getReadOnly( session ) ),
lockOptions
),
RowTransformerStandardImpl.instance(),
null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ public LockOptions getLockOptions() {
new ExecutionContextWithSubselectFetchHandler(
session,
fetchableKeysHandler( session, sqlAst, jdbcParameters, jdbcParameterBindings ),
TRUE.equals( loadOptions.getReadOnly( session ) )
TRUE.equals( loadOptions.getReadOnly( session ) ),
lockOptions
),
RowTransformerStandardImpl.instance(),
null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ interface KeyValueResolver {

private final JdbcOperationQuerySelect jdbcSelect;

private final LockOptions lockOptions;

public MultiNaturalIdLoadingBatcher(
EntityMappingType entityDescriptor,
ModelPart restrictedPart,
Expand Down Expand Up @@ -88,6 +90,7 @@ public LockOptions getLockOptions() {
return lockOptions;
}
} );
this.lockOptions = lockOptions;
}

public <E> List<E> multiLoad(Object[] naturalIdValues, SharedSessionContractImplementor session) {
Expand Down Expand Up @@ -163,7 +166,7 @@ private <E> List<E> performLoad(
return session.getJdbcServices().getJdbcSelectExecutor().list(
jdbcSelect,
jdbcParamBindings,
new ExecutionContextWithSubselectFetchHandler( session, subSelectFetchableKeysHandler ),
new ExecutionContextWithSubselectFetchHandler( session, subSelectFetchableKeysHandler, false, lockOptions ),
RowTransformerStandardImpl.instance(),
null,
ListResultsConsumer.UniqueSemantic.FILTER,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,8 @@ public void registerLoadingEntityHolder(EntityHolder holder) {
subSelectFetchableKeysHandler.addKey( holder );
}

@Override
public boolean upgradeLocks() {
return true;
}
}

0 comments on commit ca1d66f

Please sign in to comment.