I'm struggling a while for integrating Hibernate c3p0 connection pool in Jboss 5.
In my project, Hibernate is used as a JPA provider, so I use hibernate-c3p0 version 3.6.10 Final.
I use maven to build/ package the project.
In maven POM file:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-c3p0</artifactId>
<version>3.6.10.Final</version>
</dependency>
Generally, there're 2 ways to deal with this.
In 1st way, use application managed connection pool by specify database connection information in persistence.xml file, and use hibernate c3p0 integration :
In my project, Hibernate is used as a JPA provider, so I use hibernate-c3p0 version 3.6.10 Final.
I use maven to build/ package the project.
In maven POM file:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-c3p0</artifactId>
<version>3.6.10.Final</version>
</dependency>
Generally, there're 2 ways to deal with this.
In 1st way, use application managed connection pool by specify database connection information in persistence.xml file, and use hibernate c3p0 integration :
org.hibernate.connection.C3P0ConnectionProvider <property name="hibernate.connection.provider_class"></property>org.hibernate.connection.C3P0ConnectionProvider
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="hibernate.connection.url">jdbc:oracle:thin:@localhost:1521:orcl</property>
<property name="hibernate.connection.username">thinh</property>
<property name="hibernate.connection.password">password</property>
<property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property>
<property name="show_sql">true</property>
<property name="hibernate.c3p0.acquire_increment">1</property>
<property name="hibernate.c3p0.min_size">5</property>
<property name="hibernate.c3p0.max_size">20</property>
<property name="hibernate.c3p0.timeout">3000</property>
<property name="hibernate.c3p0.max_statements">50</property>
<property name="hibernate.c3p0.idle_test_period">300</property>
Another way, use container managed connection pool, by Jboss 5.
As specified here, http://www.mchange.com/projects/c3p0/#jboss-specific, with some modification:
In c3p0-service.xml file, change <mbean> tag into:
<mbean code="com.mchange.v2.c3p0.jboss.C3P0PooledDataSource" name="jboss:jca:name=PooledDS,service=DataSourceBinding">
instead of
<mbean code="com.mchange.v2.c3p0.jboss.C3P0PooledDataSource"
name="jboss:service=C3P0PooledDataSource">
In persistence.xml file, specify datasource to use (use container managed transaction):
<jta-data-source>java:/PooledDS</jta-data-source>
That's it.
No comments:
Post a Comment