HHH-16062 Apply settings and hints to criteria queries

This commit is contained in:
Marco Belladelli 2023-01-23 14:24:00 +01:00 committed by Christian Beikov
parent 136169d43a
commit eca3ff13bd
1 changed files with 11 additions and 6 deletions

View File

@ -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<Void>) criteriaUpdate, null, this );
return createCriteriaQuery( (SqmUpdateStatement<Void>) 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<Void>) criteriaDelete, null, this );
return createCriteriaQuery( (SqmDeleteStatement<Void>) criteriaDelete, null );
}
catch (RuntimeException e) {
if ( getSessionFactory().getJpaMetamodel().getJpaCompliance().isJpaTransactionComplianceEnabled() ) {
@ -1339,6 +1339,11 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont
}
}
private <T> QueryImplementor<T> createCriteriaQuery(SqmStatement<T> criteria, Class<T> resultType) {
final QuerySqmImpl<T> query = new QuerySqmImpl<>( criteria, resultType, this );
applyQuerySettingsAndHints( query );
return query;
}
private void writeObject(ObjectOutputStream oos) throws IOException {
if ( log.isTraceEnabled() ) {