简体   繁体   中英

Hibernate c3p0 and DBCP connection pooling mechanism

If you don't specify settings in hibernate.cfg.xml what will be default connection pooler and how do you change it? here is hibernate config

<hibernate-configuration>
  <session-factory>
    <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
    <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
    <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/POM_IVR</property>
    <property name="hibernate.connection.username">root</property>
    <property name="hibernate.connection.password">XXX</property>
    <property name="hibernate.show_sql">true</property>
    <property name="hibernate.current_session_context_class">thread</property>
    <property name="hibernate.query.factory_class">org.hibernate.hql.classic.ClassicQueryTranslatorFactory</property>
    <mapping resource="com/SurveyResults.hbm.xml"/>

  </session-factory>
</hibernate-configuration>

Questions 1. Does c3p0 jar come with hibernate3?

2.If you don't specify c3p0 , does hibernate use it's default connection pooler( how do you know it is not using default, is there a parameter) or DBCP?

3.How do I modify the DCBP paramater for my web application do I have to change the context file conf/catalina/locahost/Applicationame.xml in catalina or hibernate configuration, what do I have to change/add to it do I have to specify the username and password or just parameter?

4.Can someone explain how this works, hibernate request a connection and tomcat will get a connection from pool? if you specify c3p0 does DBCP get by-passed?

5.What if I have 2 web application using the same table/username/password? what is commandeered should they have their own DBCP , c3p0 jar? if conf/context.xml is applied to all application can you specify global parameter for DBCP for application to use?

This is all related to 8 hours connection timeout for mysql, I don't want to change the DB parameters.

Yes, c3p0 is part of hibernate: http://www.informit.com/articles/article.aspx?p=353736&seqNum=4

Listing 10.2 Sample Hibernate c3p0 Configuration

hibernate.c3p0.max_size=1
hibernate.c3p0.min_size=0
hibernate.c3p0.timeout=5000
hibernate.c3p0.max_statements=100
hibernate.c3p0.idle_test_period=300
hibernate.c3p0.acquire_increment=2

i believe all your answers are there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM