From eca3ff13bd30309cf6e884f7d7d73a5d1d563915 Mon Sep 17 00:00:00 2001 From: Marco Belladelli Date: Mon, 23 Jan 2023 14:24:00 +0100 Subject: [PATCH] HHH-16062 Apply settings and hints to criteria queries --- .../internal/AbstractSharedSessionContract.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/internal/AbstractSharedSessionContract.java b/hibernate-core/src/main/java/org/hibernate/internal/AbstractSharedSessionContract.java index eb42fe9f23..8d29c302e6 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/AbstractSharedSessionContract.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/AbstractSharedSessionContract.java @@ -1152,7 +1152,7 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont public MutationQuery createMutationQuery(@SuppressWarnings("rawtypes") CriteriaUpdate updateQuery) { checkOpen(); try { - return new QuerySqmImpl<>( (SqmUpdateStatement) updateQuery, null, this ); + return createCriteriaQuery( (SqmUpdateStatement) updateQuery, null ); } catch ( RuntimeException e ) { throw getExceptionConverter().convert( e ); @@ -1163,7 +1163,7 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont public MutationQuery createMutationQuery(@SuppressWarnings("rawtypes") CriteriaDelete deleteQuery) { checkOpen(); try { - return new QuerySqmImpl<>( (SqmDeleteStatement) deleteQuery, null, this ); + return createCriteriaQuery( (SqmDeleteStatement) deleteQuery, null ); } catch ( RuntimeException e ) { throw getExceptionConverter().convert( e ); @@ -1174,7 +1174,7 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont public MutationQuery createMutationQuery(@SuppressWarnings("rawtypes") JpaCriteriaInsertSelect insertSelect) { checkOpen(); try { - return new QuerySqmImpl<>( (SqmInsertSelectStatement) insertSelect, null, this ); + return createCriteriaQuery( (SqmInsertSelectStatement) insertSelect, null ); } catch ( RuntimeException e ) { throw getExceptionConverter().convert( e ); @@ -1301,7 +1301,7 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont } } - return new QuerySqmImpl<>( selectStatement, criteriaQuery.getResultType(), this ); + return createCriteriaQuery( selectStatement, criteriaQuery.getResultType() ); } catch (RuntimeException e) { if ( getSessionFactory().getJpaMetamodel().getJpaCompliance().isJpaTransactionComplianceEnabled() ) { @@ -1315,7 +1315,7 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont public QueryImplementor createQuery(@SuppressWarnings("rawtypes") CriteriaUpdate criteriaUpdate) { checkOpen(); try { - return new QuerySqmImpl<>( (SqmUpdateStatement) criteriaUpdate, null, this ); + return createCriteriaQuery( (SqmUpdateStatement) criteriaUpdate, null ); } catch (RuntimeException e) { if ( getSessionFactory().getJpaMetamodel().getJpaCompliance().isJpaTransactionComplianceEnabled() ) { @@ -1329,7 +1329,7 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont public QueryImplementor createQuery(@SuppressWarnings("rawtypes") CriteriaDelete criteriaDelete) { checkOpen(); try { - return new QuerySqmImpl<>( (SqmDeleteStatement) criteriaDelete, null, this ); + return createCriteriaQuery( (SqmDeleteStatement) criteriaDelete, null ); } catch (RuntimeException e) { if ( getSessionFactory().getJpaMetamodel().getJpaCompliance().isJpaTransactionComplianceEnabled() ) { @@ -1339,6 +1339,11 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont } } + private QueryImplementor createCriteriaQuery(SqmStatement criteria, Class resultType) { + final QuerySqmImpl query = new QuerySqmImpl<>( criteria, resultType, this ); + applyQuerySettingsAndHints( query ); + return query; + } private void writeObject(ObjectOutputStream oos) throws IOException { if ( log.isTraceEnabled() ) {