Is c3p0 connection pool is required with hibernate in JBoss AS 7

核能气质少年 提交于 2019-12-06 00:14:48

please update to c3p0-0.9.2-pre7. It's mature -- unless something unexpected comes up, the next release will be c3p0-0.9.2 final. hibernate recently added some JDBC4 dependencies. c3p0 does not yet have full JDBC4 support (it will, but after 0.9.2 is finalized), but c3p0-0.9.2-pre7 supports these methods to maintain hibernate dependency.

0.9.2-pre7 is a drop-in replacement to 0.9.1.2. simply remove c3p0-0.9.1.2.jar and replace with with BOTH c3p0-0.9.2-pre7.jar and mchange-commons-java-0.2.3.2.jar. or just use Maven central [groupId: com.mchange, artifactId: c3p0, version: 0.9.2-pre7], and let transitive dependency take care of the rest. See the very top of the docs, http://www.mchange.com/projects/c3p0/ for downloading info, etc.

c3p0 is not required with hibernate. you can use other Connection pools. but although i am biased, i think c3p0 is a pretty good choice! (i'm c3p0's author.)

Newer version of hibernate is incompatible with 0.9.1.1. I use hibernate-c3p0:4.3.0.CR1 which explicitly depends on c3p0:0.9.2.1.

Possible causes:

  • there might be some other dependency in your project which uses older version of c3p0 as transitive dependency
  • Since older group id is c3p0 and newer is com.mchange, maven might have added both of 'em to class path
  • By chance the class loader loaded classes from c3p0:c3p0:0.9.1.1 instead of com.mchange:c3p0:0.9.2.1(though the groupId changed, the packages are same)

The solution

grep for c3p0 dependency

`$mvn dependency:tree |grep -B5 "c3p0"`
[INFO] +- org.hibernate:hibernate-c3p0:jar:4.3.0.CR1:compile
[INFO] |  \- com.mchange:c3p0:jar:0.9.2.1:compile
[INFO] |     \- com.mchange:mchange-commons-java:jar:0.2.3.4:compile
--
[INFO] +- org.quartz-scheduler:quartz:jar:2.2.1:compile
[INFO] |  \- c3p0:c3p0:jar:0.9.1.1:compile

Exclude the older one!

<dependency>
    <groupId>org.quartz-scheduler</groupId>
    <artifactId>quartz</artifactId>
    <version>${quartz.version}</version>
    <exclusions>
        <exclusion>
             <groupId>c3p0</groupId>
             <artifactId>c3p0</artifactId>
             <!-- Bcoz this version is incompatible with hibernate -->
         </exclusion>
    </exclusions>
</dependency>

hibernate-core 4.2.8.Final, hibernate-c3p0 4.2.8.Final, c3p0 0.9.2.x. Had a similar problem: java.lang.AbstractMethodError: com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.setNString(ILjava/lang/String;)V

Changed c3p0 version to 0.9.5-pre6 and the problem was fixed.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!