• Post Reply Bookmark Topic Watch Topic
  • New Topic

Do select operations need a Transaction?  RSS feed

 
Ranch Hand
Posts: 578
2
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 973
9
IBM DB2 Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!