Java-2.3 JPA/Hibernate QueryTimeoutException: Could not open connection

530 views
Skip to first unread message

Johan Dahlberg

unread,
Apr 20, 2015, 3:23:53 AM4/20/15
to play-fr...@googlegroups.com
I get this error a lot currently and nothing has changed in the MySQL settings so I guess that the error has to be related to Play, Hibernate or HikariCP.

Is there anyone that has seen this error before?

play.api.Application$$anon$1: Execution exception[[QueryTimeoutException: Could not open connection]]
at play.api.Application$class.handleError(Application.scala:296) ~[com.typesafe.play.play_2.11-2.3.8.jar:2.3.8]
at play.api.DefaultApplication.handleError(Application.scala:402) [com.typesafe.play.play_2.11-2.3.8.jar:2.3.8]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$3$$anonfun$applyOrElse$4.apply(PlayDefaultUpstreamHandler.scala:320) [com.typesafe.play.play_2.11-2.3.8.jar:2.3.8]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$3$$anonfun$applyOrElse$4.apply(PlayDefaultUpstreamHandler.scala:320) [com.typesafe.play.play_2.11-2.3.8.jar:2.3.8]
at scala.Option.map(Option.scala:146) [org.scala-lang.scala-library-2.11.6.jar:na]
Caused by: javax.persistence.QueryTimeoutException: Could not open connection
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1725) ~[org.hibernate.hibernate-entitymanager-4.3.8.Final.jar:4.3.8.Final]
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1677) ~[org.hibernate.hibernate-entitymanager-4.3.8.Final.jar:4.3.8.Final]
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:1771) ~[org.hibernate.hibernate-entitymanager-4.3.8.Final.jar:4.3.8.Final]
at org.hibernate.jpa.internal.TransactionImpl.begin(TransactionImpl.java:64) ~[org.hibernate.hibernate-entitymanager-4.3.8.Final.jar:4.3.8.Final]
at play.db.jpa.JPA.withTransactionAsync(JPA.java:177) ~[com.typesafe.play.play-java-jpa_2.11-2.3.8.jar:2.3.8]
Caused by: org.hibernate.QueryTimeoutException: Could not open connection
at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:83) ~[org.hibernate.hibernate-core-4.3.8.Final.jar:4.3.8.Final]
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49) ~[org.hibernate.hibernate-core-4.3.8.Final.jar:4.3.8.Final]
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:126) ~[org.hibernate.hibernate-core-4.3.8.Final.jar:4.3.8.Final]
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:112) ~[org.hibernate.hibernate-core-4.3.8.Final.jar:4.3.8.Final]
at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.obtainConnection(LogicalConnectionImpl.java:235) ~[org.hibernate.hibernate-core-4.3.8.Final.jar:4.3.8.Final]
Caused by: java.sql.SQLTimeoutException: Timeout after 900001ms of waiting for a connection.
at com.zaxxer.hikari.pool.BaseHikariPool.getConnection(BaseHikariPool.java:228) ~[com.zaxxer.HikariCP-java6-2.3.2.jar:na]
at com.zaxxer.hikari.pool.BaseHikariPool.getConnection(BaseHikariPool.java:183) ~[com.zaxxer.HikariCP-java6-2.3.2.jar:na]
at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:91) ~[com.zaxxer.HikariCP-java6-2.3.2.jar:na]
at org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection(DatasourceConnectionProviderImpl.java:139) ~[org.hibernate.hibernate-core-4.3.8.Final.jar:4.3.8.Final]
at org.hibernate.internal.AbstractSessionImpl$NonContextualJdbcConnectionAccess.obtainConnection(AbstractSessionImpl.java:380) ~[org.hibernate.hibernate-core-4.3.8.Final.jar:4.3.8.Final]


The DB-related configuration:

db {
  default {
    driver=com.mysql.jdbc.Driver
    url="jdbc:mysql://localhost/db?tinyInt1isBit=false"
    user="******"
    password="******"
    jndiName=DefaultDS

    connectionTimeout=120 seconds
    connectionTestStatement="SELECT 1"
    idleMaxAge=10 minutes
    idleConnectionTestPeriod=30 seconds
    idleTimeout=5 minutes
    #logStatements=true
    maxConnectionAge=1 hour
    maxIdleTime=5 minutes
    maxLifetime=15 minutes
  }
}

Johan Dahlberg

unread,
Apr 20, 2015, 3:31:20 AM4/20/15
to play-fr...@googlegroups.com
I forgot to say that MySQL has 2 000 connections and this occurs even when only 100 connections has been acquired.

Johan Dahlberg

unread,
Apr 21, 2015, 2:03:02 AM4/21/15
to play-fr...@googlegroups.com
The problem was that the Thread Pool was too small.

/Johan


Den måndag 20 april 2015 kl. 09:23:53 UTC+2 skrev Johan Dahlberg:
Reply all
Reply to author
Forward
0 new messages