|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2020 the original author or authors. |
| 2 | + * Copyright 2002-2022 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
@@ -497,7 +497,7 @@ protected void doBegin(Object transaction, TransactionDefinition definition) {
|
497 | 497 | if (logger.isDebugEnabled()) {
|
498 | 498 | logger.debug("Preparing JDBC Connection of Hibernate Session [" + session + "]");
|
499 | 499 | }
|
500 |
| - Connection con = session.connection(); |
| 500 | + Connection con = session.getJdbcCoordinator().getLogicalConnection().getPhysicalConnection(); |
501 | 501 | Integer previousIsolationLevel = DataSourceUtils.prepareConnectionForTransaction(con, definition);
|
502 | 502 | txObject.setPreviousIsolationLevel(previousIsolationLevel);
|
503 | 503 | txObject.setReadOnly(definition.isReadOnly());
|
@@ -562,7 +562,9 @@ protected void doBegin(Object transaction, TransactionDefinition definition) {
|
562 | 562 |
|
563 | 563 | // Register the Hibernate Session's JDBC Connection for the DataSource, if set.
|
564 | 564 | if (getDataSource() != null) {
|
565 |
| - ConnectionHolder conHolder = new ConnectionHolder(session::connection); |
| 565 | + final SessionImplementor sessionToUse = session; |
| 566 | + ConnectionHolder conHolder = new ConnectionHolder( |
| 567 | + () -> sessionToUse.getJdbcCoordinator().getLogicalConnection().getPhysicalConnection()); |
566 | 568 | if (timeout != TransactionDefinition.TIMEOUT_DEFAULT) {
|
567 | 569 | conHolder.setTimeoutInSeconds(timeout);
|
568 | 570 | }
|
@@ -724,7 +726,7 @@ protected void doCleanupAfterCompletion(Object transaction) {
|
724 | 726 | // the isolation level and/or read-only flag of the JDBC Connection here.
|
725 | 727 | // Else, we need to rely on the connection pool to perform proper cleanup.
|
726 | 728 | try {
|
727 |
| - Connection con = session.connection(); |
| 729 | + Connection con = session.getJdbcCoordinator().getLogicalConnection().getPhysicalConnection(); |
728 | 730 | Integer previousHoldability = txObject.getPreviousHoldability();
|
729 | 731 | if (previousHoldability != null) {
|
730 | 732 | con.setHoldability(previousHoldability);
|
@@ -763,13 +765,15 @@ protected void doCleanupAfterCompletion(Object transaction) {
|
763 | 765 | /**
|
764 | 766 | * Disconnect a pre-existing Hibernate Session on transaction completion,
|
765 | 767 | * returning its database connection but preserving its entity state.
|
766 |
| - * <p>The default implementation simply calls {@link Session#disconnect()}. |
| 768 | + * <p>The default implementation calls the equivalent of {@link Session#disconnect()}. |
767 | 769 | * Subclasses may override this with a no-op or with fine-tuned disconnection logic.
|
768 | 770 | * @param session the Hibernate Session to disconnect
|
769 | 771 | * @see Session#disconnect()
|
770 | 772 | */
|
771 | 773 | protected void disconnectOnCompletion(Session session) {
|
772 |
| - session.disconnect(); |
| 774 | + if (session instanceof SessionImplementor sessionImpl) { |
| 775 | + sessionImpl.getJdbcCoordinator().getLogicalConnection().manualDisconnect(); |
| 776 | + } |
773 | 777 | }
|
774 | 778 |
|
775 | 779 | /**
|
|
0 commit comments