Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate Connection Pool

 
ujjwal soni
Ranch Hand
Posts: 403
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am using hibernate framework for generating excel reports using JXL Api.

I was using default connection pooling mechanism provided by hibernate, however, i noticed that even though i close sessions, connections and resultsets, there were many connections that remained idle and as a result after some time my Oc4j server goes out of memory.

Is there anyway i can use a single connection for all requests with hibernate ?

I also implemented C3p0 connection pooling, i downloaded latest jar file and configured as per below, but the problem still persists,



Even though max_size property is configured, it still opens new connections above range 25.

 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The default connection pool is (by the Hibernate developer's own admission) not really production quality. Its just there to get you going.

Hibernate is just grabbing the amount of connections available to it based on the connection pool's configuration. If you want to just use one connection, configure the pool to just have one available. Hibernate will return connections to the pool when you close a Session. Are you closing Sessions?
 
ujjwal soni
Ranch Hand
Posts: 403
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Paul,

Thanks for your reply.

Yes, i am closing sessions using below function :


Also, one more thing, i am using session.disconnect() in other user input module

i am using below code :


is this fine ?

If you want to just use one connection, configure the pool to just have one available.

Can you explain me how this can be done ?
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is an odd method you have there. Why are you combining ResultsSets, Statements, Connections and Sessions? And can you call flush() after you have closed the Session? It may be possible, but it seems illogical.

Disconnect will also disassociate a session from a connection.

See this
 
ujjwal soni
Ranch Hand
Posts: 403
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am closing result sets and connections because my code has some thing like this :::


do you mean that closing only session will close connection, resultset, and statements ?
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Hibernate you would not normally use Statements, ResultsSets of Connections directly - it kind of defeats the purpose of using Hibernate in the first place. Why are you choosing to do this?

If you use Hibernate as it is intended to be used, closing the Session releases database resource s back to the pool.
 
ujjwal soni
Ranch Hand
Posts: 403
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am having an existing system that was built using hibernate, this system calls stored procedures and functions directly using connections. Thats the reason i need that function to close connection, session and resultset. There are very few HQL queries in the system.

Is it a good idea to remove hibernate and use JDBC directly using servlet filter to work on a single connection ?

What do you suggest ?

 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you have more than a few stored procedures to use, Hibernate is a little pointless (unless you have a longer term plan to remove these SPs). You are tightly coupled to your database implementation, so an ORM is just an overhead. I'd use JDBC.
 
ujjwal soni
Ranch Hand
Posts: 403
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, thanks Paul...I think i should remove hibernate from the system and use Jdbc with servlet filter.

Thanks Again.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic