From 0a92d84778dcb03dd5bf2860f2d997d1db2687f4 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 25 Jan 2022 23:50:45 +0100 Subject: [PATCH] Check open status before close call (aligned with EntityManagerFactoryUtils) Closes gh-27972 --- .../springframework/orm/hibernate5/SessionFactoryUtils.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/spring-orm/src/main/java/org/springframework/orm/hibernate5/SessionFactoryUtils.java b/spring-orm/src/main/java/org/springframework/orm/hibernate5/SessionFactoryUtils.java index d3b61969aa..f9e482cd93 100644 --- a/spring-orm/src/main/java/org/springframework/orm/hibernate5/SessionFactoryUtils.java +++ b/spring-orm/src/main/java/org/springframework/orm/hibernate5/SessionFactoryUtils.java @@ -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"); * you may not use this file except in compliance with the License. @@ -133,7 +133,9 @@ public abstract class SessionFactoryUtils { public static void closeSession(@Nullable Session session) { if (session != null) { try { - session.close(); + if (session.isOpen()) { + session.close(); + } } catch (Throwable ex) { logger.error("Failed to release Hibernate Session", ex);