Check open status before close call (aligned with EntityManagerFactoryUtils)

Closes gh-27972
This commit is contained in:
Juergen Hoeller 2022-01-25 23:50:45 +01:00
parent 652c13a6ea
commit 0a92d84778
1 changed files with 4 additions and 2 deletions

View File

@ -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.
@ -133,7 +133,9 @@ public abstract class SessionFactoryUtils {
public static void closeSession(@Nullable Session session) { public static void closeSession(@Nullable Session session) {
if (session != null) { if (session != null) {
try { try {
session.close(); if (session.isOpen()) {
session.close();
}
} }
catch (Throwable ex) { catch (Throwable ex) {
logger.error("Failed to release Hibernate Session", ex); logger.error("Failed to release Hibernate Session", ex);