I have a code which gave the org.hibernate.HibernateException: The internal connection pool has reached its maximum size and no connection is currently available!. This error shows that I am not closing the transaction and since I have connection pool size set to 20, it gives the error when all connections are consumed. Below is the code:
The above code fails after 20 select statements. But when I delete the if (!transaction.isActive()) transaction.begin(); , the codes runs fine and create 30 select operations. And this time with improved speed.
The above also runs if I write transaction.commit(); statement at last. But performance is slow.
Now I am confused, is it the case that transaction is not required for Select operations?
As far as I know, almost all JPA operation require a transactional context, maybe the only exceptions are readonly select (you don't need a transaction if you're not going to change data).
Looking at your code: EntityTransaction transaction object should be local to getOutOutHeaderWithFlag method, it should not be a class member.
What happens if you instantiate an XxspAsdnOutHeaderRepo instance and reuse it ?