This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes Hibernate Connection Pool Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate Connection Pool" Watch "Hibernate Connection Pool" New topic
Author

Hibernate Connection Pool

ujjwal soni
Ranch Hand

Joined: Mar 28, 2007
Posts: 403
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.


Cheers!!!
Ujjwal B Soni <baroda, gujarat, india> <+919909981973>
"Helping hands are better than praying lips......"
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

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?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
ujjwal soni
Ranch Hand

Joined: Mar 28, 2007
Posts: 403
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

Joined: Apr 14, 2004
Posts: 10336

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

Joined: Mar 28, 2007
Posts: 403
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

Joined: Apr 14, 2004
Posts: 10336

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

Joined: Mar 28, 2007
Posts: 403
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

Joined: Apr 14, 2004
Posts: 10336

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

Joined: Mar 28, 2007
Posts: 403
Ok, thanks Paul...I think i should remove hibernate from the system and use Jdbc with servlet filter.

Thanks Again.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hibernate Connection Pool
 
Similar Threads
Connection pooling using hibernate and struts1.3
JDBCConnectionException: Cannot open connection
c3p0 project website broken... how to use it with hibernate without a container???
c3p0 pool size exceeds maxpoolsize
c3p0 configuration