Reputation: 1
On logging in with multiple users my application is throwing this exception:
Connection org.postgresql.jdbc.PgConnection@6421dd29 marked as broken because of SQLSTATE(08003), ErrorCode(0)
org.postgresql.util.PSQLException: This connection has been closed.\
Also getting:
org.springframework.transaction.CannotCreateTransactionException: Could not open Hibernate Session for transaction; nested exception is org.hibernate.TransactionException: JDBC begin transaction failed:
I have tried changing the hikari configuration and making the block synchronized.
Looks like second thread tries to make use of connection created by first thread and while second thread using it first thread close it.
Upvotes: 0
Views: 1992
Reputation: 53
Have you tried using 'Entity Transaction' to begin a transaction? you can do that following way,
Class Test{
@Autowired
EntityManagerFactory entityManagerFactory;
method(){
EntityManager manager = entityManagerFactory.createEntityManager();
EntityTransaction transaction = manager.getTransaction();
transaction.begin(); //This will start the transaction
}
}
Upvotes: 3
Reputation: 61
Spring want create transaction, but you open and already close connection. That's why Spring throws an exception org.springframework.transaction.CannotCreateTransactionException
. You must delegate connections management to Spring (uses JdbcTemplate
), or manage of the transaction manually.
Upvotes: 0