I'm using Hibernate and EntityManager 3.5.1-Final.
I'm monitoring the number of connections using pgadmin3 and I'm seeing that my application makes more connection than specified in the persistence.xml.
Here's my persistence.xml. And I'm getting and closing EntityManager for every request.
Code:
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="bank" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>com.wms.bank.entities.GameAccount</class>
<class>com.wms.bank.entities.StationAccount</class>
<class>com.wms.bank.entities.PlayerAccount</class>
<properties>
<property name="hibernate.archive.autodetection" value="none"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>
<property name="hibernate.bytecode.use_reflection_optimizer" value="false"/>
<!-- Database specific -->
<property name="hibernate.connection.driver_class" value="org.postgresql.Driver"/>
<property name="hibernate.connection.url" value="jdbc:postgresql://127.0.0.1/bank?user=postgres;password=postgres"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
<!-- Connection pool -->
<property name="hibernate.connection.provider_class" value="org.hibernate.connection.C3P0ConnectionProvider"/>
<property name="hibernate.c3p0.acquire_increment" value="0"/>
<property name="hibernate.c3p0.idle_test_period" value="100"/> <!-- seconds -->
<property name="hibernate.c3p0.max_size" value="10"/>
<property name="hibernate.c3p0.max_statements" value="0"/>
<property name="hibernate.c3p0.min_size" value="5"/>
<property name="hibernate.c3p0.timeout" value="100"/> <!-- seconds -->
</properties>
</persistence-unit>
</persistence>
Am I missing something?
Thanks