• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Do select operations need a Transaction?  RSS feed

Ranch Hand
Posts: 611
  • 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: 974
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 ?
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!