2727import org .hibernate .bytecode .enhance .spi .interceptor .SessionAssociationMarkers ;
2828import org .hibernate .cache .spi .CacheTransactionSynchronization ;
2929import org .hibernate .dialect .Dialect ;
30- import org .hibernate .engine .creation .internal .ParentSessionCallbacks ;
30+ import org .hibernate .engine .creation .internal .ParentSessionObserver ;
3131import org .hibernate .engine .creation .internal .SessionCreationOptions ;
3232import org .hibernate .engine .creation .internal .SessionCreationOptionsAdaptor ;
3333import org .hibernate .engine .creation .internal .SharedSessionBuilderImpl ;
@@ -225,15 +225,18 @@ public AbstractSharedSessionContract(SessionFactoryImpl factory, SessionCreation
225225 jdbcSessionContext = createJdbcSessionContext ( statementInspector );
226226 logInconsistentOptions ( sharedOptions );
227227 addSharedSessionTransactionObserver ( transactionCoordinator );
228- sharedOptions .registerParentSessionCallbacks ( new ParentSessionCallbacks () {
228+ sharedOptions .registerParentSessionObserver ( new ParentSessionObserver () {
229229 @ Override
230230 public void onParentFlush () {
231231 propagateFlush ();
232232 }
233233
234234 @ Override
235235 public void onParentClose () {
236- propagateClose ();
236+ // unless explicitly disabled, propagate the closure
237+ if ( sharedOptions .shouldAutoClose () ) {
238+ propagateClose ();
239+ }
237240 }
238241 } );
239242 }
@@ -505,13 +508,6 @@ public boolean isClosed() {
505508
506509 @ Override
507510 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-
515511 if ( !closed || waitingForAutoClose ) {
516512 try {
517513 delayedAfterCompletion ();
@@ -915,7 +911,7 @@ public void setNativeJdbcParametersIgnored(boolean nativeJdbcParametersIgnored)
915911 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
916912 // dynamic HQL handling
917913
918- @ Override @ SuppressWarnings ("rawtypes" )
914+ @ Override @ Deprecated @ SuppressWarnings ({ "rawtypes" , "deprecation" } )
919915 public QueryImplementor createQuery (String queryString ) {
920916 return createQuery ( queryString , null );
921917 }
@@ -1017,10 +1013,12 @@ public <R> QueryImplementor<R> createQuery(TypedQueryReference<R> typedQueryRefe
10171013 checksBeforeQueryCreation ();
10181014 if ( typedQueryReference instanceof SelectionSpecificationImpl <R > specification ) {
10191015 final var query = specification .buildCriteria ( getCriteriaBuilder () );
1016+ //noinspection unchecked
10201017 return new SqmQueryImpl <>( (SqmStatement <R >) query , specification .getResultType (), this );
10211018 }
10221019 else if ( typedQueryReference instanceof MutationSpecificationImpl <?> specification ) {
10231020 final var query = specification .buildCriteria ( getCriteriaBuilder () );
1021+ //noinspection unchecked
10241022 return new SqmQueryImpl <>( (SqmStatement <R >) query , (Class <R >) specification .getResultType (), this );
10251023 }
10261024 else {
@@ -1039,12 +1037,12 @@ else if ( typedQueryReference instanceof MutationSpecificationImpl<?> specificat
10391037 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10401038 // dynamic native (SQL) query handling
10411039
1042- @ Override
1040+ @ Override @ Deprecated @ SuppressWarnings ( "deprecation" )
10431041 public NativeQueryImplementor <?> createNativeQuery (String sqlString ) {
10441042 return createNativeQuery ( sqlString , (Class <?>) null );
10451043 }
10461044
1047- @ Override
1045+ @ Override @ Deprecated @ SuppressWarnings ( "deprecation" )
10481046 public NativeQueryImplementor <?> createNativeQuery (String sqlString , String resultSetMappingName ) {
10491047 checksBeforeQueryCreation ();
10501048 return buildNativeQuery ( sqlString , resultSetMappingName , null );
@@ -1146,7 +1144,7 @@ public QueryImplementor<?> getNamedQuery(String queryName) {
11461144 return createNamedQuery ( queryName );
11471145 }
11481146
1149- @ Override
1147+ @ Override @ Deprecated @ SuppressWarnings ( "deprecation" )
11501148 public QueryImplementor <?> createNamedQuery (String name ) {
11511149 checksBeforeQueryCreation ();
11521150 try {
@@ -1253,12 +1251,14 @@ protected <T,Q extends CommonQueryContract> Q buildNamedQuery(
12531251 // first see if it is a named HQL query
12541252 final var namedSqmQueryMemento = getSqmQueryMemento ( queryName );
12551253 if ( namedSqmQueryMemento != null ) {
1254+ //noinspection unchecked
12561255 return sqmCreator .apply ( (NamedSqmQueryMemento <T >) namedSqmQueryMemento );
12571256 }
12581257
12591258 // otherwise, see if it is a named native query
12601259 final var namedNativeDescriptor = getNativeQueryMemento ( queryName );
12611260 if ( namedNativeDescriptor != null ) {
1261+ //noinspection unchecked
12621262 return nativeCreator .apply ( (NamedNativeQueryMemento <T >) namedNativeDescriptor );
12631263 }
12641264
@@ -1322,7 +1322,7 @@ protected <T> SqmQueryImplementor<T> createSqmQueryImplementor(Class<T> resultTy
13221322 return query ;
13231323 }
13241324
1325- @ Override
1325+ @ Override @ Deprecated @ SuppressWarnings ( "deprecation" )
13261326 public NativeQueryImplementor <?> getNamedNativeQuery (String queryName ) {
13271327 final var namedNativeDescriptor = getNativeQueryMemento ( queryName );
13281328 if ( namedNativeDescriptor != null ) {
@@ -1333,7 +1333,7 @@ public NativeQueryImplementor<?> getNamedNativeQuery(String queryName) {
13331333 }
13341334 }
13351335
1336- @ Override
1336+ @ Override @ Deprecated @ SuppressWarnings ( "deprecation" )
13371337 public NativeQueryImplementor <?> getNamedNativeQuery (String queryName , String resultSetMapping ) {
13381338 final var namedNativeDescriptor = getNativeQueryMemento ( queryName );
13391339 if ( namedNativeDescriptor != null ) {
@@ -1590,7 +1590,7 @@ public <T> QueryImplementor<T> createQuery(CriteriaQuery<T> criteriaQuery) {
15901590 }
15911591 }
15921592
1593- @ Override
1593+ @ Override @ Deprecated @ SuppressWarnings ( "deprecation" )
15941594 public QueryImplementor <?> createQuery (@ SuppressWarnings ("rawtypes" ) CriteriaUpdate criteriaUpdate ) {
15951595 checkOpen ();
15961596 try {
@@ -1602,7 +1602,7 @@ public QueryImplementor<?> createQuery(@SuppressWarnings("rawtypes") CriteriaUpd
16021602 }
16031603 }
16041604
1605- @ Override
1605+ @ Override @ Deprecated @ SuppressWarnings ( "deprecation" )
16061606 public QueryImplementor <?> createQuery (@ SuppressWarnings ("rawtypes" ) CriteriaDelete criteriaDelete ) {
16071607 checkOpen ();
16081608 try {
0 commit comments