diff --git a/hibernate-core/src/main/java/org/hibernate/query/spi/AbstractSelectionQuery.java b/hibernate-core/src/main/java/org/hibernate/query/spi/AbstractSelectionQuery.java index e6f0fd741e97..4edccdf2a934 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/spi/AbstractSelectionQuery.java +++ b/hibernate-core/src/main/java/org/hibernate/query/spi/AbstractSelectionQuery.java @@ -181,17 +181,28 @@ protected void beforeQuery() { session.prepareForQueryExecution( requiresTxn( options.getLockOptions().getLockMode() ) ); prepareForExecution(); + prepareSessionFlushMode( session ); + prepareSessionCacheMode( session ); + } + /* + * Used by Hibernate Reactive + */ + protected void prepareSessionFlushMode(SharedSessionContractImplementor session) { assert sessionFlushMode == null; - assert sessionCacheMode == null; - - final FlushMode effectiveFlushMode = getQueryOptions().getFlushMode(); + final var effectiveFlushMode = getQueryOptions().getFlushMode(); if ( effectiveFlushMode != null && session instanceof SessionImplementor statefulSession ) { sessionFlushMode = statefulSession.getHibernateFlushMode(); statefulSession.setHibernateFlushMode( effectiveFlushMode ); } + } - final CacheMode effectiveCacheMode = getCacheMode(); + /* + * Used by Hibernate Reactive + */ + protected void prepareSessionCacheMode(SharedSessionContractImplementor session) { + assert sessionCacheMode == null; + final var effectiveCacheMode = getCacheMode(); if ( effectiveCacheMode != null ) { sessionCacheMode = session.getCacheMode(); session.setCacheMode( effectiveCacheMode ); diff --git a/hibernate-core/src/main/java/org/hibernate/query/sql/internal/NativeQueryImpl.java b/hibernate-core/src/main/java/org/hibernate/query/sql/internal/NativeQueryImpl.java index dd66e3708035..f8c850083b93 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sql/internal/NativeQueryImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sql/internal/NativeQueryImpl.java @@ -568,6 +568,14 @@ public boolean hasCallbackActions() { return callback != null && callback.hasAfterLoadActions(); } + /* + * Used by Hibernate Reactive + */ + @Override + protected void resetCallback() { + callback = null; + } + @Override public QueryParameterBindings getQueryParameterBindings() { return parameterBindings; @@ -736,14 +744,17 @@ protected void prepareForExecution() { getSession().flush(); } // Reset the callback before every execution - callback = null; + resetCallback(); } // Otherwise, the application specified query spaces via the Hibernate // SynchronizeableQuery and so the query will already perform a partial // flush according to the defined query spaces - no need for a full flush. } - private boolean shouldFlush() { + /* + * Used by Hibernate Reactive + */ + protected boolean shouldFlush() { if ( getSession().isTransactionInProgress() ) { final FlushMode flushMode = getQueryOptions().getFlushMode(); return switch ( flushMode == null ? getSession().getHibernateFlushMode() : flushMode ) {