Skip to content

Commit b7591a9

Browse files
committed
add StatelessSessionBuilder.connectionHandling() to match SessionBuilder
1 parent 5ca21e6 commit b7591a9

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

hibernate-core/src/main/java/org/hibernate/StatelessSessionBuilder.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,18 @@ public interface StatelessSessionBuilder {
3333
*/
3434
StatelessSessionBuilder connection(Connection connection);
3535

36+
/**
37+
* Specifies the connection handling modes for the session.
38+
* <p>
39+
* Note that if {@link ConnectionAcquisitionMode#IMMEDIATELY} is specified,
40+
* then the release mode must be {@link ConnectionReleaseMode#ON_CLOSE}.
41+
*
42+
* @return {@code this}, for method chaining
43+
*
44+
* @since 7.2
45+
*/
46+
StatelessSessionBuilder connectionHandling(ConnectionAcquisitionMode acquisitionMode, ConnectionReleaseMode releaseMode);
47+
3648
/**
3749
* Define the tenant identifier to be associated with the opened session.
3850
*

hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1396,6 +1396,7 @@ public static class StatelessSessionBuilderImpl implements StatelessSessionBuild
13961396
private final SessionFactoryImpl sessionFactory;
13971397
private StatementInspector statementInspector;
13981398
private Connection connection;
1399+
private PhysicalConnectionHandlingMode connectionHandlingMode;
13991400
private Object tenantIdentifier;
14001401
private boolean readOnly;
14011402
private CacheMode cacheMode;
@@ -1406,6 +1407,7 @@ public StatelessSessionBuilderImpl(SessionFactoryImpl sessionFactory) {
14061407
statementInspector = options.getStatementInspector();
14071408
cacheMode = options.getInitialSessionCacheMode();
14081409
tenantIdentifier = sessionFactory.resolveTenantIdentifier();
1410+
connectionHandlingMode = options.getPhysicalConnectionHandlingMode();
14091411
}
14101412

14111413
@Override
@@ -1419,6 +1421,12 @@ public StatelessSessionBuilder connection(Connection connection) {
14191421
return this;
14201422
}
14211423

1424+
@Override
1425+
public StatelessSessionBuilder connectionHandling(ConnectionAcquisitionMode acquisitionMode, ConnectionReleaseMode releaseMode) {
1426+
this.connectionHandlingMode = PhysicalConnectionHandlingMode.interpret( acquisitionMode, releaseMode);
1427+
return this;
1428+
}
1429+
14221430
@Override @Deprecated
14231431
public StatelessSessionBuilder tenantIdentifier(String tenantIdentifier) {
14241432
this.tenantIdentifier = tenantIdentifier;
@@ -1509,7 +1517,7 @@ public StatementInspector getStatementInspector() {
15091517

15101518
@Override
15111519
public PhysicalConnectionHandlingMode getPhysicalConnectionHandlingMode() {
1512-
return sessionFactory.getSessionFactoryOptions().getPhysicalConnectionHandlingMode();
1520+
return connectionHandlingMode;
15131521
}
15141522

15151523
@Override

0 commit comments

Comments
 (0)