These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Please helping in understanding datasource ..c3p0? DBCP?
PostPosted: Mon Aug 17, 2009 1:45 am 
Newbie

Joined: Sat Nov 01, 2008 3:58 pm
Posts: 7
Ok, I'm upset so I hope it doesn't come off that way too badly in this question.

The docs and the JPA with Hibernate book are incredibly confusing on this issue of datasources. Google doesn't help much either since many things that come up are outdated or when I've seen this question asked, it seems to remain unanswered.

I understand I can use an external datasource configured for my application container, but I'm still determined to set up a datasource other than the default (whatever that is?) in Hibernate directly in my hibernate config file. I've used DBCP before, but have completely given up trying to get that work to in hibernate, so I figured I'd use C3P0 - but even though I follow the same properties shown here: https://www.hibernate.org/214.html, I still get the message " Using Hibernate built-in connection pool (not for production use!)"

So how do I use C3P0??? or DBCP???

You'd think this would be covered with some good detail, but it doesn't seem to be. (Also, why do people assume that their server's pool will be that much better? If you aren't in a clustered environment what are apps like Tomat using anyway? My guess is something like DBCP.. so there should be a way I could configure the app to use dbcp or c3p0 without even having to rely on an external server config file. Just set up c3p0 in your hibernate config and be done. However, I can't seem to not get that message about hibernate using the default connection pool. (Is maybe c3p0 it's default? If so, that message should be cleared up.)

How are others setting up their datasource to use c3p0? Thanks so much for some help here.


Top
 Profile  
 
 Post subject: Re: Please helping in understanding datasource ..c3p0? DBCP?
PostPosted: Mon Aug 17, 2009 10:24 am 
Newbie

Joined: Sat Nov 01, 2008 3:58 pm
Posts: 7
To follow up the docs imply that the default pool is NOT c3p0, so how do I get c3p0 to be used? I've added the properties exactly like they are shown in the doc below, but I still get the warning on initialization of the SessionFactory.

Quote:
Hibernate's own connection pooling algorithm is, however, quite rudimentary. It is intended to help you get started and is not intended for use in a production system, or even for performance testing. You should use a third party pool for best performance and stability. Just replace the hibernate.connection.pool_size property with connection pool specific settings. This will turn off Hibernate's internal pool. For example, you might like to use c3p0.

C3P0 is an open source JDBC connection pool distributed along with Hibernate in the lib directory. Hibernate will use its org.hibernate.connection.C3P0ConnectionProvider for connection pooling if you set hibernate.c3p0.* properties. If you would like to use Proxool, refer to the packaged hibernate.properties and the Hibernate web site for more information.

The following is an example hibernate.properties file for c3p0:

Code:
hibernate.connection.driver_class = org.postgresql.Driver
hibernate.connection.url = jdbc:postgresql://localhost/mydatabase
hibernate.connection.username = myuser
hibernate.connection.password = secret
hibernate.c3p0.min_size=5
hibernate.c3p0.max_size=20
hibernate.c3p0.timeout=1800
hibernate.c3p0.max_statements=50
hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect


Top
 Profile  
 
 Post subject: Re: Please helping in understanding datasource ..c3p0? DBCP?
PostPosted: Mon Aug 17, 2009 1:41 pm 
Newbie

Joined: Sat Nov 01, 2008 3:58 pm
Posts: 7
Ok, in case anyone gets here from searching, I figured out the problem...

starting with 3.4.GA you need an optional hibernate-c3p0 jar (not just the c3p0 jar) from Maven at this time the dependency is:
Code:
<dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-c3p0</artifactId>
            <version>3.3.1.GA</version>
</dependency>


Then like mentioned in some of the other notes you need to declare your using c3p0:

<property name="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>

whoosho. Hope the docs were updated with this info.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.