From 23850a1b731214ad3730a3172cadbc935f70b6d5 Mon Sep 17 00:00:00 2001 From: Adam Saghy Date: Thu, 19 Dec 2024 17:55:12 +0100 Subject: [PATCH] FINERACT-2081: Fix `Connection is not available, request timed out after 30000ms` issue of "read-only" check --- .../core/persistence/ExtendedJpaTransactionManager.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/fineract-core/src/main/java/org/apache/fineract/infrastructure/core/persistence/ExtendedJpaTransactionManager.java b/fineract-core/src/main/java/org/apache/fineract/infrastructure/core/persistence/ExtendedJpaTransactionManager.java index c8716ff835..37b04b999f 100644 --- a/fineract-core/src/main/java/org/apache/fineract/infrastructure/core/persistence/ExtendedJpaTransactionManager.java +++ b/fineract-core/src/main/java/org/apache/fineract/infrastructure/core/persistence/ExtendedJpaTransactionManager.java @@ -25,6 +25,7 @@ import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; import java.util.function.Consumer; +import org.springframework.jdbc.datasource.DataSourceUtils; import org.springframework.jdbc.datasource.JdbcTransactionObjectSupport; import org.springframework.orm.jpa.EntityManagerHolder; import org.springframework.orm.jpa.JpaTransactionManager; @@ -65,10 +66,13 @@ protected void doCommit(DefaultTransactionStatus status) { } public boolean isReadOnlyConnection() { - try (Connection connection = getDataSource().getConnection()) { + Connection connection = DataSourceUtils.getConnection(getDataSource()); + try { return connection.isReadOnly(); } catch (SQLException e) { throw new IllegalStateException(e); + } finally { + DataSourceUtils.releaseConnection(connection, getDataSource()); } }