Skip to content

Commit c3ebcd2

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

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,16 +180,28 @@ protected void beforeQuery() {
180180

181181
session.prepareForQueryExecution( requiresTxn( options.getLockOptions().getLockMode() ) );
182182
prepareForExecution();
183+
prepareSessionFlushMode( session );
184+
prepareSessionCacheMode( session );
185+
}
183186

184-
assert sessionFlushMode == null;
185-
assert sessionCacheMode == null;
186187

188+
/*
189+
* Used by Hibernate Reactive
190+
*/
191+
protected void prepareSessionFlushMode(SharedSessionContractImplementor session) {
192+
assert sessionFlushMode == null;
187193
final var effectiveFlushMode = getQueryOptions().getFlushMode();
188194
if ( effectiveFlushMode != null && session instanceof SessionImplementor statefulSession ) {
189195
sessionFlushMode = statefulSession.getHibernateFlushMode();
190196
statefulSession.setHibernateFlushMode( effectiveFlushMode );
191197
}
198+
}
192199

200+
/*
201+
* Used by Hibernate Reactive
202+
*/
203+
protected void prepareSessionCacheMode(SharedSessionContractImplementor session) {
204+
assert sessionCacheMode == null;
193205
final var effectiveCacheMode = getCacheMode();
194206
if ( effectiveCacheMode != null ) {
195207
sessionCacheMode = session.getCacheMode();

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,14 @@ public boolean hasCallbackActions() {
554554
return callback != null && callback.hasAfterLoadActions();
555555
}
556556

557+
/*
558+
* Used by Hibernate Reactive
559+
*/
560+
@Override
561+
protected void resetCallback() {
562+
callback = null;
563+
}
564+
557565
@Override
558566
public QueryParameterBindings getQueryParameterBindings() {
559567
return parameterBindings;
@@ -722,14 +730,17 @@ protected void prepareForExecution() {
722730
getSession().flush();
723731
}
724732
// Reset the callback before every execution
725-
callback = null;
733+
resetCallback();
726734
}
727735
// Otherwise, the application specified query spaces via the Hibernate
728736
// SynchronizeableQuery and so the query will already perform a partial
729737
// flush according to the defined query spaces - no need for a full flush.
730738
}
731739

732-
private boolean shouldFlush() {
740+
/*
741+
* Used by Hibernate Reactive
742+
*/
743+
protected boolean shouldFlush() {
733744
if ( getSession().isTransactionInProgress() ) {
734745
final var flushMode = getQueryOptions().getFlushMode();
735746
return switch ( flushMode == null ? getSession().getHibernateFlushMode() : flushMode ) {

0 commit comments

Comments
 (0)