Compatibility with Hibernate 6.0/6.1 (for transitional purposes)
Closes gh-28813
This commit is contained in:
parent
cabd126fb8
commit
7a042062f5
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2020 the original author or authors.
|
* Copyright 2002-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -497,7 +497,7 @@ public class HibernateTransactionManager extends AbstractPlatformTransactionMana
|
||||||
if (logger.isDebugEnabled()) {
|
if (logger.isDebugEnabled()) {
|
||||||
logger.debug("Preparing JDBC Connection of Hibernate Session [" + session + "]");
|
logger.debug("Preparing JDBC Connection of Hibernate Session [" + session + "]");
|
||||||
}
|
}
|
||||||
Connection con = session.connection();
|
Connection con = session.getJdbcCoordinator().getLogicalConnection().getPhysicalConnection();
|
||||||
Integer previousIsolationLevel = DataSourceUtils.prepareConnectionForTransaction(con, definition);
|
Integer previousIsolationLevel = DataSourceUtils.prepareConnectionForTransaction(con, definition);
|
||||||
txObject.setPreviousIsolationLevel(previousIsolationLevel);
|
txObject.setPreviousIsolationLevel(previousIsolationLevel);
|
||||||
txObject.setReadOnly(definition.isReadOnly());
|
txObject.setReadOnly(definition.isReadOnly());
|
||||||
|
|
@ -562,7 +562,9 @@ public class HibernateTransactionManager extends AbstractPlatformTransactionMana
|
||||||
|
|
||||||
// Register the Hibernate Session's JDBC Connection for the DataSource, if set.
|
// Register the Hibernate Session's JDBC Connection for the DataSource, if set.
|
||||||
if (getDataSource() != null) {
|
if (getDataSource() != null) {
|
||||||
ConnectionHolder conHolder = new ConnectionHolder(session::connection);
|
final SessionImplementor sessionToUse = session;
|
||||||
|
ConnectionHolder conHolder = new ConnectionHolder(
|
||||||
|
() -> sessionToUse.getJdbcCoordinator().getLogicalConnection().getPhysicalConnection());
|
||||||
if (timeout != TransactionDefinition.TIMEOUT_DEFAULT) {
|
if (timeout != TransactionDefinition.TIMEOUT_DEFAULT) {
|
||||||
conHolder.setTimeoutInSeconds(timeout);
|
conHolder.setTimeoutInSeconds(timeout);
|
||||||
}
|
}
|
||||||
|
|
@ -724,7 +726,7 @@ public class HibernateTransactionManager extends AbstractPlatformTransactionMana
|
||||||
// the isolation level and/or read-only flag of the JDBC Connection here.
|
// the isolation level and/or read-only flag of the JDBC Connection here.
|
||||||
// Else, we need to rely on the connection pool to perform proper cleanup.
|
// Else, we need to rely on the connection pool to perform proper cleanup.
|
||||||
try {
|
try {
|
||||||
Connection con = session.connection();
|
Connection con = session.getJdbcCoordinator().getLogicalConnection().getPhysicalConnection();
|
||||||
Integer previousHoldability = txObject.getPreviousHoldability();
|
Integer previousHoldability = txObject.getPreviousHoldability();
|
||||||
if (previousHoldability != null) {
|
if (previousHoldability != null) {
|
||||||
con.setHoldability(previousHoldability);
|
con.setHoldability(previousHoldability);
|
||||||
|
|
@ -763,13 +765,15 @@ public class HibernateTransactionManager extends AbstractPlatformTransactionMana
|
||||||
/**
|
/**
|
||||||
* Disconnect a pre-existing Hibernate Session on transaction completion,
|
* Disconnect a pre-existing Hibernate Session on transaction completion,
|
||||||
* returning its database connection but preserving its entity state.
|
* returning its database connection but preserving its entity state.
|
||||||
* <p>The default implementation simply calls {@link Session#disconnect()}.
|
* <p>The default implementation calls the equivalent of {@link Session#disconnect()}.
|
||||||
* Subclasses may override this with a no-op or with fine-tuned disconnection logic.
|
* Subclasses may override this with a no-op or with fine-tuned disconnection logic.
|
||||||
* @param session the Hibernate Session to disconnect
|
* @param session the Hibernate Session to disconnect
|
||||||
* @see Session#disconnect()
|
* @see Session#disconnect()
|
||||||
*/
|
*/
|
||||||
protected void disconnectOnCompletion(Session session) {
|
protected void disconnectOnCompletion(Session session) {
|
||||||
session.disconnect();
|
if (session instanceof SessionImplementor sessionImpl) {
|
||||||
|
sessionImpl.getJdbcCoordinator().getLogicalConnection().manualDisconnect();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2020 the original author or authors.
|
* Copyright 2002-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -19,6 +19,7 @@ package org.springframework.orm.hibernate5;
|
||||||
import org.hibernate.FlushMode;
|
import org.hibernate.FlushMode;
|
||||||
import org.hibernate.Session;
|
import org.hibernate.Session;
|
||||||
import org.hibernate.SessionFactory;
|
import org.hibernate.SessionFactory;
|
||||||
|
import org.hibernate.engine.spi.SessionImplementor;
|
||||||
|
|
||||||
import org.springframework.core.Ordered;
|
import org.springframework.core.Ordered;
|
||||||
import org.springframework.dao.DataAccessException;
|
import org.springframework.dao.DataAccessException;
|
||||||
|
|
@ -69,7 +70,10 @@ public class SpringSessionSynchronization implements TransactionSynchronization,
|
||||||
if (this.holderActive) {
|
if (this.holderActive) {
|
||||||
TransactionSynchronizationManager.unbindResource(this.sessionFactory);
|
TransactionSynchronizationManager.unbindResource(this.sessionFactory);
|
||||||
// Eagerly disconnect the Session here, to make release mode "on_close" work on JBoss.
|
// Eagerly disconnect the Session here, to make release mode "on_close" work on JBoss.
|
||||||
getCurrentSession().disconnect();
|
Session session = getCurrentSession();
|
||||||
|
if (session instanceof SessionImplementor sessionImpl) {
|
||||||
|
sessionImpl.getJdbcCoordinator().getLogicalConnection().manualDisconnect();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -106,7 +110,9 @@ public class SpringSessionSynchronization implements TransactionSynchronization,
|
||||||
session.setHibernateFlushMode(this.sessionHolder.getPreviousFlushMode());
|
session.setHibernateFlushMode(this.sessionHolder.getPreviousFlushMode());
|
||||||
}
|
}
|
||||||
// Eagerly disconnect the Session here, to make release mode "on_close" work nicely.
|
// Eagerly disconnect the Session here, to make release mode "on_close" work nicely.
|
||||||
session.disconnect();
|
if (session instanceof SessionImplementor sessionImpl) {
|
||||||
|
sessionImpl.getJdbcCoordinator().getLogicalConnection().manualDisconnect();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
// Unbind at this point if it's a new Session...
|
// Unbind at this point if it's a new Session...
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue