Skip to content

Commit 5e08598

Browse files
committed
HibernateJpaDialect accepts equivalent connection for proper reset as well
Issue: SPR-14393
1 parent f5282bc commit 5e08598

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

spring-orm/src/main/java/org/springframework/orm/jpa/vendor/HibernateJpaDialect.java

+12-2
Original file line numberDiff line numberDiff line change
@@ -362,15 +362,25 @@ public void resetSessionState() {
362362
}
363363
if (this.preparedCon != null && this.session.isConnected()) {
364364
Connection conToReset = HibernateConnectionHandle.doGetConnection(this.session);
365-
if (conToReset != this.preparedCon) {
365+
if (!isEquivalentConnection(conToReset)) {
366366
LogFactory.getLog(HibernateJpaDialect.class).warn(
367-
"JDBC Connection to reset not identical to originally prepared Connection - please " +
367+
"JDBC Connection to reset not equivalent to originally prepared Connection - please " +
368368
"make sure to use connection release mode ON_CLOSE (the default) and to run against " +
369369
"Hibernate 4.2+ (or switch HibernateJpaDialect's prepareConnection flag to false");
370370
}
371371
DataSourceUtils.resetConnectionAfterTransaction(conToReset, this.previousIsolationLevel);
372372
}
373373
}
374+
375+
private boolean isEquivalentConnection(Connection con) {
376+
try {
377+
return (con.equals(this.preparedCon) ||
378+
con.unwrap(Connection.class).equals(this.preparedCon.unwrap(Connection.class)));
379+
}
380+
catch (Throwable ex) {
381+
return false;
382+
}
383+
}
374384
}
375385

376386

0 commit comments

Comments
 (0)