Skip to content

Commit 9321f10

Browse files
committed
HHH-19977 Relax scope to allo HR to run a reactive flush
A native query might need to run a flush operation before it's executed. Hibernate Reactive runs a reactive flush. By relaxing the scopes of these methods, we can avoid some code duplication.
1 parent 527325f commit 9321f10

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

hibernate-core/src/main/java/org/hibernate/query/spi/AbstractSelectionQuery.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,16 +181,27 @@ protected void beforeQuery() {
181181

182182
session.prepareForQueryExecution( requiresTxn( options.getLockOptions().getLockMode() ) );
183183
prepareForExecution();
184+
prepareSessionFlushMode( session );
185+
prepareSessionCacheMode( session );
186+
}
184187

188+
/*
189+
* Used by Hibernate Reactive
190+
*/
191+
protected void prepareSessionFlushMode(SharedSessionContractImplementor session) {
185192
assert sessionFlushMode == null;
186-
assert sessionCacheMode == null;
187-
188-
final FlushMode effectiveFlushMode = getQueryOptions().getFlushMode();
193+
final var effectiveFlushMode = getQueryOptions().getFlushMode();
189194
if ( effectiveFlushMode != null && session instanceof SessionImplementor statefulSession ) {
190195
sessionFlushMode = statefulSession.getHibernateFlushMode();
191196
statefulSession.setHibernateFlushMode( effectiveFlushMode );
192197
}
198+
}
193199

200+
/*
201+
* Used by Hibernate Reactive
202+
*/
203+
protected void prepareSessionCacheMode(SharedSessionContractImplementor session) {
204+
assert sessionCacheMode == null;
194205
final CacheMode effectiveCacheMode = getCacheMode();
195206
if ( effectiveCacheMode != null ) {
196207
sessionCacheMode = session.getCacheMode();

hibernate-core/src/main/java/org/hibernate/query/sql/internal/NativeQueryImpl.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -736,14 +736,17 @@ protected void prepareForExecution() {
736736
getSession().flush();
737737
}
738738
// Reset the callback before every execution
739-
callback = null;
739+
resetCallback();
740740
}
741741
// Otherwise, the application specified query spaces via the Hibernate
742742
// SynchronizeableQuery and so the query will already perform a partial
743743
// flush according to the defined query spaces - no need for a full flush.
744744
}
745745

746-
private boolean shouldFlush() {
746+
/*
747+
* Used by Hibernate Reactive
748+
*/
749+
protected boolean shouldFlush() {
747750
if ( getSession().isTransactionInProgress() ) {
748751
final FlushMode flushMode = getQueryOptions().getFlushMode();
749752
return switch ( flushMode == null ? getSession().getHibernateFlushMode() : flushMode ) {

0 commit comments

Comments
 (0)