HibernateJpaDialect accepts equivalent connection for proper reset as well

Issue: SPR-14393
This commit is contained in:
Juergen Hoeller 2016-06-23 18:24:09 +02:00
parent f5282bc1e3
commit 5e08598a2a
1 changed files with 12 additions and 2 deletions

View File

@ -362,15 +362,25 @@ public class HibernateJpaDialect extends DefaultJpaDialect {
}
if (this.preparedCon != null && this.session.isConnected()) {
Connection conToReset = HibernateConnectionHandle.doGetConnection(this.session);
if (conToReset != this.preparedCon) {
if (!isEquivalentConnection(conToReset)) {
LogFactory.getLog(HibernateJpaDialect.class).warn(
"JDBC Connection to reset not identical to originally prepared Connection - please " +
"JDBC Connection to reset not equivalent to originally prepared Connection - please " +
"make sure to use connection release mode ON_CLOSE (the default) and to run against " +
"Hibernate 4.2+ (or switch HibernateJpaDialect's prepareConnection flag to false");
}
DataSourceUtils.resetConnectionAfterTransaction(conToReset, this.previousIsolationLevel);
}
}
private boolean isEquivalentConnection(Connection con) {
try {
return (con.equals(this.preparedCon) ||
con.unwrap(Connection.class).equals(this.preparedCon.unwrap(Connection.class)));
}
catch (Throwable ex) {
return false;
}
}
}