Search code examples
javajakarta-eejpac3p0

Verify c3p0 running with JPA


I'm using JPA for my persistence for my project and don't really know anything about hibernate but most tutorials I follow have found to setup connection pooling use c3p0 and hibernate.

Heres my persistence.xml file

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
  <persistence-unit name="Cinemango308PU" transaction-type="RESOURCE_LOCAL">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <class>JPA.Ad</class>
    <class>JPA.Photo</class>
    <class>JPA.Theatre</class>
    <class>JPA.Creditcard</class>
    <class>JPA.Moviereview</class>
    <class>JPA.Giftcard</class>
    <class>JPA.Showtime</class>
    <class>JPA.Ticket</class>
    <class>JPA.Favoritetheatres</class>
    <class>JPA.User</class>
    <class>JPA.Actor</class>
    <class>JPA.Movie</class>
    <class>JPA.Theatrerewards</class>
    <class>JPA.Payment</class>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties>
      <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:5432/cinemango>
      <property name="javax.persistence.jdbc.user" value="xxxx"/>
      <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
      <property name="javax.persistence.jdbc.password" value="xxxxxx"/>
      <property name="javax.persistence.schema-generation.database.action" value="create"/>

      <!-- Configuring Connection Pool -->
      <property name="connection.provider_class" value="org.hibernate.connection.C3P0ConnectionProvider" />

          <property name="hibernate.c3p0.max_size" value="5" />
          <property name="hibernate.c3p0.min_size" value="0" />
          <property name="hibernate.c3p0.acquire_increment" value="1" />
          <property name="hibernate.c3p0.idle_test_period" value="300" />
          <property name="hibernate.c3p0.max_statements" value="0" />
          <property name="hibernate.c3p0.timeout" value="100" />
    </properties>
  </persistence-unit>
</persistence>

How do i test if the connection pooling is working? I don't see a log displayed to my output


Solution

  • Please find the logging configuration here http://www.mchange.com/projects/c3p0/#configuring_logging

    There you can find how to switch on debug to see if pooling happens.