Issue
I'm using the EntityManagerFactory
from Hibernate and have a connectionPoolSize of 20. Now I have some larger queries (t> 30 min) that take up my pool completely. When I start a new query (with getEntityManager) I get the following exception:
javax.persistence.PersistenceException: org.hibernate.HibernateException:
The internal connection pool has reached its maximum size and no connection is currently available!
at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:154)
at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:181)
at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1538)
at org.hibernate.query.Query.getResultList(Query.java:165)
Are there any comfort features that put my thread to sleep until a connection is available?
I only use standard functions:
public static EntityManager getEntityManager () {
return emFactory.createEntityManager ();
}
The Creation of my EntityManagerFactory:
public static void createEntityManagerFactory(String hostname, Integer port, String driver,
String database, boolean validate, int maxConnections, Properties properties) {
Properties props = new Properties();
props.setProperty("hibernate.connection.url", "jdbc:" + driver + ":thin:@" + hostname + ":" + port + ":" + database);
props.setProperty("hibernate.connection.driver_class", "oracle.jdbc.driver.OracleDriver");
props.setProperty("hibernate.connection.username", properties.getProperty("user"));
props.setProperty("hibernate.connection.password", properties.getProperty("password"));
props.setProperty("hibernate.dialect", "org.hibernate.dialect.Oracle10gDialect");
emFactory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME, props);
}
My persistence.xml contains:
<property name="connection.pool_size" value="20" />
I read about C3P0 settings, could they help me?
-- UPDATE -- I had some problems with C3P0 (for example: ORA-01652: unable to extend temp segment by 128 in tablespace SYSTEM even with a small number of maximum connection pool size), that I didnt have with hibernate vanilla. -- Configuration c3p0
<property name="hibernate.c3p0.min_size" value ="2"/>
<property name="hibernate.c3p0.max_size" value ="10"/>
<property name="hibernate.c3p0.acquire_increment" value ="2"/>
<property name="hibernate.c3p0.idle_test_period" value ="100"/>
<property name="hibernate.c3p0.timeout" value ="3600"/>
Solution
Ive solved this problem with using hikaricp for connection pooling.
Answered By - MavidDeyers
Answer Checked By - Robin (JavaFixing Admin)