27
27
import org .hibernate .bytecode .enhance .spi .interceptor .SessionAssociationMarkers ;
28
28
import org .hibernate .cache .spi .CacheTransactionSynchronization ;
29
29
import org .hibernate .dialect .Dialect ;
30
- import org .hibernate .engine .creation .internal .ParentSessionCallbacks ;
30
+ import org .hibernate .engine .creation .internal .ParentSessionObserver ;
31
31
import org .hibernate .engine .creation .internal .SessionCreationOptions ;
32
32
import org .hibernate .engine .creation .internal .SessionCreationOptionsAdaptor ;
33
33
import org .hibernate .engine .creation .internal .SharedSessionBuilderImpl ;
@@ -225,15 +225,18 @@ public AbstractSharedSessionContract(SessionFactoryImpl factory, SessionCreation
225
225
jdbcSessionContext = createJdbcSessionContext ( statementInspector );
226
226
logInconsistentOptions ( sharedOptions );
227
227
addSharedSessionTransactionObserver ( transactionCoordinator );
228
- sharedOptions .registerParentSessionCallbacks ( new ParentSessionCallbacks () {
228
+ sharedOptions .registerParentSessionObserver ( new ParentSessionObserver () {
229
229
@ Override
230
230
public void onParentFlush () {
231
231
propagateFlush ();
232
232
}
233
233
234
234
@ Override
235
235
public void onParentClose () {
236
- propagateClose ();
236
+ // unless explicitly disabled, propagate the closure
237
+ if ( sharedOptions .shouldAutoClose () ) {
238
+ propagateClose ();
239
+ }
237
240
}
238
241
} );
239
242
}
@@ -505,13 +508,6 @@ public boolean isClosed() {
505
508
506
509
@ Override
507
510
public void close () {
508
- if ( isTransactionCoordinatorShared ) {
509
- // Perform an auto-flush -
510
- // This deals with the natural usage pattern of a child Session
511
- // used with a try-with-resource block
512
- propagateFlush ();
513
- }
514
-
515
511
if ( !closed || waitingForAutoClose ) {
516
512
try {
517
513
delayedAfterCompletion ();
@@ -915,7 +911,7 @@ public void setNativeJdbcParametersIgnored(boolean nativeJdbcParametersIgnored)
915
911
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
916
912
// dynamic HQL handling
917
913
918
- @ Override @ SuppressWarnings ("rawtypes" )
914
+ @ Override @ Deprecated @ SuppressWarnings ({ "rawtypes" , "deprecation" } )
919
915
public QueryImplementor createQuery (String queryString ) {
920
916
return createQuery ( queryString , null );
921
917
}
@@ -1017,10 +1013,12 @@ public <R> QueryImplementor<R> createQuery(TypedQueryReference<R> typedQueryRefe
1017
1013
checksBeforeQueryCreation ();
1018
1014
if ( typedQueryReference instanceof SelectionSpecificationImpl <R > specification ) {
1019
1015
final var query = specification .buildCriteria ( getCriteriaBuilder () );
1016
+ //noinspection unchecked
1020
1017
return new SqmQueryImpl <>( (SqmStatement <R >) query , specification .getResultType (), this );
1021
1018
}
1022
1019
else if ( typedQueryReference instanceof MutationSpecificationImpl <?> specification ) {
1023
1020
final var query = specification .buildCriteria ( getCriteriaBuilder () );
1021
+ //noinspection unchecked
1024
1022
return new SqmQueryImpl <>( (SqmStatement <R >) query , (Class <R >) specification .getResultType (), this );
1025
1023
}
1026
1024
else {
@@ -1039,12 +1037,12 @@ else if ( typedQueryReference instanceof MutationSpecificationImpl<?> specificat
1039
1037
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1040
1038
// dynamic native (SQL) query handling
1041
1039
1042
- @ Override
1040
+ @ Override @ Deprecated @ SuppressWarnings ( "deprecation" )
1043
1041
public NativeQueryImplementor <?> createNativeQuery (String sqlString ) {
1044
1042
return createNativeQuery ( sqlString , (Class <?>) null );
1045
1043
}
1046
1044
1047
- @ Override
1045
+ @ Override @ Deprecated @ SuppressWarnings ( "deprecation" )
1048
1046
public NativeQueryImplementor <?> createNativeQuery (String sqlString , String resultSetMappingName ) {
1049
1047
checksBeforeQueryCreation ();
1050
1048
return buildNativeQuery ( sqlString , resultSetMappingName , null );
@@ -1146,7 +1144,7 @@ public QueryImplementor<?> getNamedQuery(String queryName) {
1146
1144
return createNamedQuery ( queryName );
1147
1145
}
1148
1146
1149
- @ Override
1147
+ @ Override @ Deprecated @ SuppressWarnings ( "deprecation" )
1150
1148
public QueryImplementor <?> createNamedQuery (String name ) {
1151
1149
checksBeforeQueryCreation ();
1152
1150
try {
@@ -1253,12 +1251,14 @@ protected <T,Q extends CommonQueryContract> Q buildNamedQuery(
1253
1251
// first see if it is a named HQL query
1254
1252
final var namedSqmQueryMemento = getSqmQueryMemento ( queryName );
1255
1253
if ( namedSqmQueryMemento != null ) {
1254
+ //noinspection unchecked
1256
1255
return sqmCreator .apply ( (NamedSqmQueryMemento <T >) namedSqmQueryMemento );
1257
1256
}
1258
1257
1259
1258
// otherwise, see if it is a named native query
1260
1259
final var namedNativeDescriptor = getNativeQueryMemento ( queryName );
1261
1260
if ( namedNativeDescriptor != null ) {
1261
+ //noinspection unchecked
1262
1262
return nativeCreator .apply ( (NamedNativeQueryMemento <T >) namedNativeDescriptor );
1263
1263
}
1264
1264
@@ -1322,7 +1322,7 @@ protected <T> SqmQueryImplementor<T> createSqmQueryImplementor(Class<T> resultTy
1322
1322
return query ;
1323
1323
}
1324
1324
1325
- @ Override
1325
+ @ Override @ Deprecated @ SuppressWarnings ( "deprecation" )
1326
1326
public NativeQueryImplementor <?> getNamedNativeQuery (String queryName ) {
1327
1327
final var namedNativeDescriptor = getNativeQueryMemento ( queryName );
1328
1328
if ( namedNativeDescriptor != null ) {
@@ -1333,7 +1333,7 @@ public NativeQueryImplementor<?> getNamedNativeQuery(String queryName) {
1333
1333
}
1334
1334
}
1335
1335
1336
- @ Override
1336
+ @ Override @ Deprecated @ SuppressWarnings ( "deprecation" )
1337
1337
public NativeQueryImplementor <?> getNamedNativeQuery (String queryName , String resultSetMapping ) {
1338
1338
final var namedNativeDescriptor = getNativeQueryMemento ( queryName );
1339
1339
if ( namedNativeDescriptor != null ) {
@@ -1590,7 +1590,7 @@ public <T> QueryImplementor<T> createQuery(CriteriaQuery<T> criteriaQuery) {
1590
1590
}
1591
1591
}
1592
1592
1593
- @ Override
1593
+ @ Override @ Deprecated @ SuppressWarnings ( "deprecation" )
1594
1594
public QueryImplementor <?> createQuery (@ SuppressWarnings ("rawtypes" ) CriteriaUpdate criteriaUpdate ) {
1595
1595
checkOpen ();
1596
1596
try {
@@ -1602,7 +1602,7 @@ public QueryImplementor<?> createQuery(@SuppressWarnings("rawtypes") CriteriaUpd
1602
1602
}
1603
1603
}
1604
1604
1605
- @ Override
1605
+ @ Override @ Deprecated @ SuppressWarnings ( "deprecation" )
1606
1606
public QueryImplementor <?> createQuery (@ SuppressWarnings ("rawtypes" ) CriteriaDelete criteriaDelete ) {
1607
1607
checkOpen ();
1608
1608
try {
0 commit comments