From d12619cf1f7a772440622c8102d6bca1cf46b5be Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Wed, 12 Feb 2020 16:48:42 +0100 Subject: [PATCH] Raise log level for exceptions from EntityManager close call Closes gh-24501 --- .../jms/connection/SingleConnectionFactory.java | 4 ++-- .../orm/hibernate5/SessionFactoryUtils.java | 7 ++----- .../springframework/orm/jpa/EntityManagerFactoryUtils.java | 7 ++----- .../org/springframework/orm/jpa/JpaTransactionManager.java | 6 +++--- 4 files changed, 9 insertions(+), 15 deletions(-) diff --git a/spring-jms/src/main/java/org/springframework/jms/connection/SingleConnectionFactory.java b/spring-jms/src/main/java/org/springframework/jms/connection/SingleConnectionFactory.java index bc1f74c48c30..84b2378ab056 100644 --- a/spring-jms/src/main/java/org/springframework/jms/connection/SingleConnectionFactory.java +++ b/spring-jms/src/main/java/org/springframework/jms/connection/SingleConnectionFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2020 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. @@ -505,7 +505,7 @@ protected void closeConnection(Connection con) { logger.debug("Ignoring Connection state exception - assuming already closed: " + ex); } catch (Throwable ex) { - logger.debug("Could not close shared JMS Connection", ex); + logger.warn("Could not close shared JMS Connection", ex); } } 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 79b0cecf2fe6..87ba5cc2a071 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-2018 the original author or authors. + * Copyright 2002-2020 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. @@ -170,11 +170,8 @@ public static void closeSession(@Nullable Session session) { try { session.close(); } - catch (HibernateException ex) { - logger.debug("Could not close Hibernate Session", ex); - } catch (Throwable ex) { - logger.debug("Unexpected exception on closing Hibernate Session", ex); + logger.error("Failed to release Hibernate Session", ex); } } } diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/EntityManagerFactoryUtils.java b/spring-orm/src/main/java/org/springframework/orm/jpa/EntityManagerFactoryUtils.java index b5a148ed3d84..e8fb5e15fb8c 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/EntityManagerFactoryUtils.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/EntityManagerFactoryUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2020 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. @@ -427,11 +427,8 @@ public static void closeEntityManager(@Nullable EntityManager em) { em.close(); } } - catch (PersistenceException ex) { - logger.debug("Could not close JPA EntityManager", ex); - } catch (Throwable ex) { - logger.debug("Unexpected exception on closing JPA EntityManager", ex); + logger.error("Failed to release JPA EntityManager", ex); } } } diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/JpaTransactionManager.java b/spring-orm/src/main/java/org/springframework/orm/jpa/JpaTransactionManager.java index 5c33b474d1c5..c4c1385cca73 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/JpaTransactionManager.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/JpaTransactionManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2020 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. @@ -603,9 +603,9 @@ protected void doCleanupAfterCompletion(Object transaction) { getJpaDialect().releaseJdbcConnection(conHandle, txObject.getEntityManagerHolder().getEntityManager()); } - catch (Exception ex) { + catch (Throwable ex) { // Just log it, to keep a transaction-related exception. - logger.error("Could not close JDBC connection after transaction", ex); + logger.error("Failed to release JDBC connection after transaction", ex); } } }