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()); } }