Search code examples
javahibernatejdbcjboss7.xconnection-pooling

Is Hibernate also use connection pool as JDBC?


I use JBOSS 7.1 web server for my application. I configured JBOSS connection pool and use it for JDBC connections. I also use hibernate in my application. And i want to know if hibernate also use this connection pool or me need to configure other connection pool(for example c3p0) for hibernate?


Solution

  • hibernate.cfg.xml

    <?xml version="1.0" encoding="utf-8"?>
    <!DOCTYPE hibernate-configuration PUBLIC
    "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
    <hibernate-configuration>
     <session-factory>
      <property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
      <property name="hibernate.connection.url">jdbc:oracle:thin:@localhost:1521:schema</property>
      <property name="hibernate.connection.username">user</property>
      <property name="hibernate.connection.password">password</property>
      <property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property>
      <property name="hibernate.default_schema">schema</property>
      <property name="show_sql">true</property>
    
      <property name="hibernate.c3p0.min_size">5</property>
      <property name="hibernate.c3p0.max_size">20</property>
      <property name="hibernate.c3p0.timeout">300</property>
      <property name="hibernate.c3p0.max_statements">50</property>
      <property name="hibernate.c3p0.idle_test_period">3000</property>
    

    hibernate.c3p0.min_size – Minimum number of JDBC connections in the pool. Hibernate default: 1
    hibernate.c3p0.max_size – Maximum number of JDBC connections in the pool. Hibernate default: 100
    hibernate.c3p0.timeout – When an idle connection is removed from the pool (in second). Hibernate default: 0, never expire.
    hibernate.c3p0.max_statements – Number of prepared statements will be cached. Increase performance. Hibernate default: 0 , caching is disable.
    hibernate.c3p0.idle_test_period – idle time in seconds before a connection is automatically validated. Hibernate default: 0
    

    more detail refer link