kaya
kaya

Reputation: 1666

Connection pool has reached its maximum size

I have changed my app from java7 to java8 as i wanted to try and use lambda expression on a method.

Afterwards i had to upgrade tomcat7 to tomcat8 as it didnt want to run my webservice anymore.

Now since i changed it to tomcat8, i have a problem with the connection pool :\

What did do so far? Searched SO and google but could not find anything related to my problem, beside of C3P0 settings which i am not so experienced yet.

<property name="connection_provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>
<property name="c3p0.minPoolSize">5</property>
<property name="c3p0.maxPoolSize">100</property>
<property name="c3p0.acquireIncrement">5</property>
<property name="c3p0.maxStatements">200</property>
<property name="c3p0.timeout">180</property>

Does anyone have an idea for me, or do i have to revert back to java7 as i didnt had any problems yesterday.

EDIT: added exception msg

SCHWERWIEGEND: Servlet.service() for servlet [RESTservice] in context with path [] threw exception [org.hibernate.HibernateException: The internal connection pool has reached its maximum size and no connection is currently available!] with root cause org.hibernate.HibernateException: The internal connection pool has reached its maximum size and no connection is currently available!

EDIT 17.08.2016: I recoded the app as suggested in the link, it was not that much to change, only add entitymanager dependency and create a persistence.xml from the existing hibernate.cfg.xml.

The source needed a few changes in the implementation so far, i already had Annotations and persistence imports and it was not that a difference to the Hibernate Syntax.

But did i do it correct? I created a single JPA instance in this case a EntityManager in the constructor and am using it everywhere, do i still need to close and recreate it everywhere?

At least the problem im facing at the moment is this exception which doesnt let me experiment further.

javax.persistence.PersistenceException: No Persistence provider for EntityManager named ServicePU

my persistence.xml:

<?xml version="1.0" encoding="UTF-8"?>
<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="ServicePU">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <properties>
            <property name="hibernate.connection.url" value="jdbc:sqlserver://xyz" />
            <property name="hibernate.connection.driver_class" value="com.microsoft.sqlserver.jdbc.SQLServerDriver" />
            <property name="hibernate.connection.username" value="xyz" />
            <property name="hibernate.connection.password" value="xyz" />
            <property name="hibernate.archive.autodetection" value="class" />
            <property name="hibernate.show_sql" value="true" />
            <property name="hibernate.format_sql" value="true" />
            <property name="hbm2ddl.auto" value="update" />
        </properties>
    </persistence-unit>
</persistence>

I hope the MSSQL driver isnt the problem here :=)

Upvotes: 0

Views: 7089

Answers (2)

J.Redwood
J.Redwood

Reputation: 1

I had this issue on updating Tomcat - it was caused by not explicitly stating the way the public key generation is handled on one of my entity classes (using the @GeneratedValue annotation).

I also get the same exception if using GenerationType.AUTO instead of IDENTITY (which is used for an auto-increment primary key)

public class myExampleClass {

@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="id")
private int id;

Upvotes: 2

naoru
naoru

Reputation: 2227

It looks like you are not closing your transactions after each access to the DB. I would recommend using JPA entity manager or my personal preference using spring framework , anyway this link provides and easy example http://www.javawebtutor.com/articles/jpa/jpa-example-using-maven.php

Upvotes: 1

Related Questions