Skip to content
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 @@ -34,7 +34,7 @@ public class NaturalIdMultiLoadAccessStandard<T> implements NaturalIdMultiLoadAc

private Integer batchSize;
private boolean returnOfDeletedEntitiesEnabled;
private boolean orderedReturnEnabled = true;
private boolean orderedReturnEnabled = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this default changed? The jdoc of NaturalIdMultiLoadAccess#enableOrderedReturn says:

By default, the returned list is ordered and the positions of the
entities correspond to the positions of their ids. [...]

This seems to break that assumption, no?


public NaturalIdMultiLoadAccessStandard(EntityPersister entityDescriptor, SessionImpl session) {
this.entityDescriptor = entityDescriptor;
Expand Down
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;
}
}
Loading