简体   繁体   English

c3p0池不起作用(在tomcat上具有休眠和数据源)

[英]c3p0 pooling is not working (with hibernate and a datasource, on tomcat)

We have a java web application running on tomcat 6, which is calling a jar for persistance. 我们在tomcat 6上运行了一个Java Web应用程序,该应用程序正在调用jar以实现持久性。 This jar is located in the tomcat lib folder, and uses a tomcat datasource : 该jar位于tomcat的lib文件夹中,并使用tomcat数据源:

<Resource name="jdbc/mydatasource"
          auth="Container"
          type="javax.sql.DataSource"
          username="USER"
          password="PASSWORD"
          driverClassName="org.postgresql.Driver"
          url="jdbc:postgresql://HOST:5432/DATABASE"/>

The jar is the binary of a java project, which uses hibernate 3.5.6-Final for ORM. 该jar是Java项目的二进制文件,该项目将休眠3.5.6-Final用于ORM。 The hibernate configuration is the following : 休眠配置如下:

    <property name="hibernate.c3p0.min_size">5</property>
    <property name="hibernate.c3p0.max_size">20</property>
    <property name="hibernate.c3p0.timeout">1800</property>
    <property name="hibernate.c3p0.max_statements">50</property>
    <property name="hibernate.connection.datasource">java:jdbc/mydatasource</property> 
    <property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property> 

At first, we did not include the hibernate-c3p0 bundle in the application, so the c3p0 settings were not used. 首先,我们没有在应用程序中包含hibernate-c3p0软件包,因此未使用c3p0设置。 And the whole application works fine like this. 整个应用程序可以像这样正常工作。

We added the hibernate-c3p0 bundle, in order to enable a better pooling management. 我们添加了hibernate-c3p0捆绑包,以实现更好的池管理。 So this bundle is now embedded in the jar for persistance. 因此,此捆绑包现在已嵌入jar中以保持持久性。

But we have now this error (it appears after each startup, when the weba pplication tries to retrieve data from the persistance jar) : 但是我们现在有了这个错误(每次启动后,当weba应用程序尝试从持久性jar中检索数据时,就会出现此错误):

[Task-Thread-for-com.mchange.v2.async.ThreadPerTaskAsynchronousRunner@eafa5f] 13 :46:22 WARN - BasicResourcePool$AcquireTask: () com.mchange.v2.resourcepool.Basi cResourcePool$AcquireTask@b321c1 -- Acquisition Attempt Failed!!! [Task-Thread-for-com.mchange.v2.async.ThreadPerTaskAsynchronousRunner@eafa5f] 13:46:22 WARN-BasicResourcePool $ AcquireTask:()com.mchange.v2.resourcepool.Basi cResourcePool $ AcquireTask @ b321c1-尝试获取失败! Clearing pendi ng acquires. 结算笔获得。 While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30). 在尝试获取所需的新资源时,我们未能成功超过允许的最大尝试获取次数(30)。 Last acquisi tion attempt exception: java.lang.NullPointerException at sun.jdbc.odbc.JdbcOdbcDriver.getProtocol(JdbcOdbcDriver.java:507) at sun.jdbc.odbc.JdbcOdbcDriver.knownURL(JdbcOdbcDriver.java:476) at sun.jdbc.odbc.JdbcOdbcDriver.acceptsURL(JdbcOdbcDriver.java:307) at java.sql.DriverManager.getDriver(DriverManager.java:253) at com.mchange.v2.c3p0.DriverManagerDataSource.driver(DriverManagerDataS ource.java:224) at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManag erDataSource.java:120) at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnecti on(WrapperConnectionPoolDataSource.java:143) at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnecti on(WrapperConnectionPoolDataSource.java:132) at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionRe sourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:137) at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResource Pool.java:1014) at com.mchange.v2 最后一次尝试获取异常:sun.jdbc.odbc.JdbcOdbcDriver.knownURL(JdbcOdbcDriver.knownURL(JdbcOdbcDriver.java:476)处的sun.jdbc.odbc.JdbcOdbcDriver.java:507处的java.lang.NullPointerException com上的com.mchange.v2.c3p0.DriverManagerDataSource.driver(DriverManagerDataS ource.java:224)上的java.sql.DriverManager.getDriver(DriverManager.java:253)上的odbc.JdbcOdbcDriver.acceptsURL(JdbcOdbcDriver.java:307)位于com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnecti on(WrapperConnectionPoolDataSource.java:143)上的mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManag erDataSource.java:120)在com.mchange.v2.c3pPool.Source (WrapperConnectionPoolDataSource.java:132)在com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool $ 1PooledConnectionRe sourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:137)在com.mchange.v2.resourcepool.BasicResourcePool.do ),网址为com.mchange.v2 .resourcepool.BasicResourcePool.access$800(BasicResourc ePool.java:32) at com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicRe sourcePool.java:1810) at com.mchange.v2.async.ThreadPerTaskAsynchronousRunner$TaskThread.run(T hreadPerTaskAsynchronousRunner.java:255) .resourcepool.BasicResourcePool.access $ 800(BasicResourc ePool.java:32)位于com.mchange.v2.resourcepool.BasicResourcePool $ AcquireTask.run(BasicRe sourcePool.java:1810)位于com.mchange.v2.async.ThreadPerTaskAsynchronousRunner $ Task运行(T hreadPerTaskAsynchronousRunner.java:255)

This seems wrong because the Ojdbc driver seems to be used instead of the postgresql driver defined in the datasource. 这似乎是错误的,因为似乎使用了Ojdbc驱动程序而不是数据源中定义的postgresql驱动程序。

Do you know what can make this error appear, and how to solve it ? 您知道什么可以使此错误出现以及如何解决吗?

I tried different things in the hibernate configuration, that i found in stackoverflow and different forums, which do not solve the problem : 我在休眠配置中尝试了不同的方法,这些问题在stackoverflow和不同的论坛中发现,但不能解决问题:

<property name="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>

    <property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
    <property name="driverClass">org.postgresql.Driver</property>
    <property name="hibernate.c3p0.driverClass">org.postgresql.Driver</property>

I must precise that we only have under our control the jar used for persistance and the tomcat installation. 我必须指出,我们只能控制用于持久性和tomcat安装的jar。 We cannot modify the web application which is calling the jar. 我们无法修改正在调用jar的Web应用程序。

Maybe your app is not be going to a Tomcat configured datasource at all, is just working through hibernate? 也许您的应用程序根本不会使用Tomcat配置的数据源,只是通过休眠工作? Have you tried skipping the Resource XML (which isn't quite right for a c3p0 DataSource anyway), and just configuring hibernate for c3p0? 您是否尝试过跳过Resource XML(无论如何对于c3p0数据源来说都是不合适的),而只是为c3p0配置了休眠模式?

<!-- add these -->
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.connection.url">jdbc:postgresql://HOST:5432/DATABASE</property>
<property name="hibernate.connection.username">USER</property>
<property name="hibernate.connection.password">PASSWORD</property>

<!-- same as before -->
<property name="hibernate.c3p0.min_size">5</property>
<property name="hibernate.c3p0.max_size">20</property>
<property name="hibernate.c3p0.timeout">1800</property>
<property name="hibernate.c3p0.max_statements">50</property>
<property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property> 

<!-- REMOVE THIS! -->
<!-- <property name="hibernate.connection.datasource">java:jdbc/mydatasource</property> --> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM