2

I wanted to migrate our Java servlet to use Hikari Connection Pool instead of C3P0. However, I have encountered a strange bug - during the Hibernate bootup, the servlet crashes with :

Method org.postgresql.jdbc4.Jdbc4Connection.isValid(int) is not yet implemented.

This is a weird behaviour, as we are using the newest JDBC41 postgresql driver, excerpt from our pom.xml:

<dependency>
   <groupId>org.postgresql</groupId>
   <artifactId>postgresql</artifactId>
   <version>9.3-1102-jdbc41</version>
</dependency>

and according to the changelog of JDBC driver, the isValid() method should already be properly implemented in 9.3-1102. We were using this version of the driver with C3P0 and had absolutely no problems.

We have also tried using the Pgsql-NG JDBC driver which was working correctly, but was buggy when handling the PostGIS datatypes.

I also tried setting up the connectionTestQuery in the Hikari configuration to SELECT 1 to force Hikari not to use the isValid(), but this had no effect.

Has anyone some experiences with this problem or some workarounds?

4

1 回答 1

3

如果使用弹簧,试试这个:

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

<bean id="hikariConfig" class="com.zaxxer.hikari.HikariConfig">
    <property name="poolName" value="springHikariCP" />
    <property name="dataSourceClassName" value="org.postgresql.ds.PGSimpleDataSource" />
    <property name="maximumPoolSize" value="30" />
    <property name="connectionTestQuery" value="select 1"/>
    <property name="dataSourceProperties">
        <props>
            <prop key="serverName">${jdbc.serverName}</prop>
            <prop key="portNumber">${jdbc.portNumber}</prop>
            <prop key="databaseName">${jdbc.databaseName}</prop>
            <prop key="user">${jdbc.user}</prop>
            <prop key="password">${jdbc.password}</prop>
        </props>
    </property>
</bean>

SELECT 1内部替换为isValid(),性能没问题

版本:

    <dependency>
        <groupId>com.zaxxer</groupId>
        <artifactId>HikariCP</artifactId>
        <version>2.4.1</version>
        <scope>compile</scope>
    </dependency>

    <dependency>
        <groupId>org.postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <version>9.3-1103-jdbc41</version>
    </dependency>
于 2015-08-26T20:37:43.217 回答