• Post Reply Bookmark Topic Watch Topic
  • New Topic

Database connection per hibernate session

 
Haris Dautovic
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I working on my web services application.
Here is configuration :
- Apache Tomcat/7.0.37
- hibernate 3.0
- mysql-connector-java-5.1.24-bin.jar

I make some test function that call database every 2 minutes.



After 2 minutes i have exception: http://pastebin.com/4kLjwMBG

I spend few days searching about this problem.

Now i know thats problem in database connection time_out value, in my database this is set on 60 second.


I find solution for my problem, when i do something with hibernate before that i create new database connection for current hibernate session.



and now all working fine but i think this is not a good solution for my problem because open connection every time when working with database is cost much.

I read about database connection pooling mechanism and i dont know what is best option for my case.
What you think about my current solution (database connection per hibernate session)..

thanks in advance,

Regards,
haris




 
Paul Clapham
Sheriff
Posts: 21878
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Haris Dautovic wrote:and now all working fine but i think this is not a good solution for my problem because open connection every time when working with database is cost much.

I read about database connection pooling mechanism and i dont know what is best option for my case.
What you think about my current solution (database connection per hibernate session)..



I don't see why opening a database connection once every two minutes is a problem. What is this "cost much" that you are talking about?

And, welcome to the Ranch!
 
Carles Gasques
Ranch Hand
Posts: 199
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Haris,

Also notice that the pooled connections gonna have the same issue (1 minut idle timeout ) hence the pool gonna create a new connection as you have to do/configure.

You can keep alive the connection implementing some kind of heartbeat inexpensive query ( Oracle example could be "Select user from dual") every 59''.


Cheers,
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!