C3p0 with Hibernate 4.2 error: setCharacterStream(

2019-05-14 01:13发布

问题:

I am using Hibernate 4.2 with c3p0 and I am getting this error:Method com/mchange/v2/c3p0/impl/NewProxyPreparedStatement.setCharacterStream(ILjava/io/Reader;J)V is abstract

Anybody knows which version should I use? Here is my current Maven dependencies list:

<dependency>
    <groupId>com.mchange</groupId>
    <artifactId>c3p0</artifactId>
    <version>0.9.2</version>
</dependency>

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-c3p0</artifactId>
    <version>4.2.0.Final</version>
</dependency>        

回答1:

The PreparedStatement.setCharacterStream() method was added to JDBC 4 and according to C3P0 release notes:

As of version 0.9.5, c3p0 fully supports the jdbc4 spec.

So you need to update the C3p0 library to 0.9.5:

<dependency>
    <groupId>com.mchange</groupId>
    <artifactId>c3p0</artifactId>
    <version>0.9.5</version>
</dependency>

You might also exclude the C3P0 dependency from Hibernate, to make sure Maven uses the one you configured explicitly:

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-c3p0</artifactId>
    <version>4.2.0.Final</version>
    <exclusions>
        <exclusion>
            <artifactId>c3p0</artifactId>
            <groupId>c3p0</groupId>
        </exclusion>
    </exclusions>
</dependency>


回答2:

use artifactId c3p0 0.9.5.2 it's ok!

<dependency>
    <groupId>com.mchange</groupId>
    <artifactId>c3p0</artifactId>
    <version>0.9.5.2</version>
</dependency>


回答3:

In my case after migration to hibernate 4 I had to add c3p0-0.9.5.jar and mchange-commons-java-0.2.15.jar (jar, becouse it is not maven project)