Search code examples
javaspringpostgresqlhikaricp

HikariCP with PostgreSQL: setQueryTimeout(int) is not yet implemented


I tried to use HikariCP with PostgreSQL but it doesn't work. It throws an exception:

WARN  [2014-10-24 14:38:54,195] com.zaxxer.hikari.pool.HikariPool: Exception during keep alive check, that means the connection must be dead.
    ! org.postgresql.util.PSQLException: Method org.postgresql.jdbc4.Jdbc4Statement.setQueryTimeout(int) is not yet implemented.
    ! at org.postgresql.Driver.notImplemented(Driver.java:753) ~[postgresql-9.0-801.jdbc4.jar:na]
    ! at org.postgresql.jdbc2.AbstractJdbc2Statement.setQueryTimeout(AbstractJdbc2Statement.java:656) ~[postgresql-9.0-801.jdbc4.jar:na]
    ! at com.zaxxer.hikari.pool.HikariPool.isConnectionAlive(HikariPool.java:473) [HikariCP-java6-2.1.0.jar:na]
    ! at com.zaxxer.hikari.pool.HikariPool.getConnection(HikariPool.java:178) [HikariCP-java6-2.1.0.jar:na]
    ! at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:94) [HikariCP-java6-2.1.0.jar:na]

I tried all possible driver versions (including org.postgresql:postgresql:9.3-1102-jdbc41) - nothing helped. Did anybody use it with PostgreSQL?

Here is my config file:

<bean id="hikariConfig" class="com.zaxxer.hikari.HikariConfig">
    <property name="connectionTestQuery" value="SELECT 1" />
    <property name="dataSourceClassName" value="org.postgresql.ds.PGSimpleDataSource" />
    <property name="maximumPoolSize" value="${jdbc.maximumPoolSize:20}" />
    <property name="idleTimeout" value="${jdbc.idleTimeout:600000}" />

    <property name="dataSourceProperties">
        <props>
            <prop key="databaseName">vidsearch_test</prop>
            <prop key="user">${hibernate.connection.username}</prop>
            <prop key="password">${hibernate.connection.password}</prop>
        </props>
    </property>
</bean>

<bean id="dataSource" class="com.zaxxer.hikari.HikariDataSource" destroy-method="close">
    <constructor-arg ref="hikariConfig"/>
</bean>

Solution

  • Don't use a connectionTestQuery. Allow HikariCP to follow its default behavior of using the Connection.isValid() method. This requires a JDBC4 driver.