From 0841dc5f99e004554c66dcb36981bf63e82ddd95 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Mon, 3 Dec 2018 18:27:30 +0100 Subject: [PATCH] Restore Hibernate ORM 5.1 compatibility in HibernateTransactionManager Issue: SPR-17557 --- .../orm/hibernate5/HibernateTransactionManager.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/spring-orm/src/main/java/org/springframework/orm/hibernate5/HibernateTransactionManager.java b/spring-orm/src/main/java/org/springframework/orm/hibernate5/HibernateTransactionManager.java index 50f4ad47a6..40efca4c7c 100644 --- a/spring-orm/src/main/java/org/springframework/orm/hibernate5/HibernateTransactionManager.java +++ b/spring-orm/src/main/java/org/springframework/orm/hibernate5/HibernateTransactionManager.java @@ -541,7 +541,10 @@ public class HibernateTransactionManager extends AbstractPlatformTransactionMana // Register the Hibernate Session's JDBC Connection for the DataSource, if set. if (getDataSource() != null) { SessionImplementor sessionImpl = (SessionImplementor) session; - ConnectionHolder conHolder = new ConnectionHolder(sessionImpl::connection); + // The following needs to use a lambda expression instead of a method reference + // for compatibility with Hibernate ORM <5.2 where connection() is defined on + // SessionImplementor itself instead of on SharedSessionContractImplementor... + ConnectionHolder conHolder = new ConnectionHolder(() -> sessionImpl.connection()); if (timeout != TransactionDefinition.TIMEOUT_DEFAULT) { conHolder.setTimeoutInSeconds(timeout); }