• 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 ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Do select operations need a Transaction?  RSS feed

 
Ranch Hand
Posts: 626
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 Foreman
Posts: 1026
24
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!