的persistence.xml
<properties>
<property name='javax.persistence.jdbc.driver' value='org.postgresql.Driver' />
<property name='javax.persistence.jdbc.url'
value='jdbc:postgresql://192.168.19.66:5432/service1' />
<property name='javax.persistence.jdbc.user' value='postgres' />
<property name='javax.persistence.jdbc.password' value='root' />
<property name='hibernate.dialect' value='org.hibernate.dialect.PostgreSQLDialect' />
<property name='hibernate.connection.shutdown' value='true' />
<property name='hibernate.hbm2ddl.auto' value='none' />
<property name='hibernate.show_sql' value='false' />
<property name='hibernate.format_sql' value='false' />
<!-- Connection Pooling -->
<property name="hibernate.connection.provider_class"
value="org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider" />
<property name="hibernate.c3p0.max_size" value="100" />
<property name="hibernate.c3p0.min_size" value="5" />
<property name="hibernate.c3p0.acquire_increment" value="5" />
<property name="hibernate.c3p0.idle_test_period" value="500" />
<property name="hibernate.c3p0.max_statements" value="50" />
<property name="hibernate.c3p0.timeout" value="10000" />
</properties>
异常
[C3P0PooledConnectionPoolManager[identityToken->1hge4qw8wh4gndjoawud4|b81be4]-AdminTaskTimer] DEBUG com.mchange.v2.async.ThreadPoolAsynchronousRunner - com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@5d1aef -- Running DeadlockDetector[Exiting. No pending tasks.]
[C3P0PooledConnectionPoolManager[identityToken->1hge4qw8wh4gndjoawud4|b81be4]-AdminTaskTimer] DEBUG com.mchange.v2.resourcepool.BasicResourcePool - Continuing acquisition series. pending_acquires [5], attempts_remaining: 20
[C3P0PooledConnectionPoolManager[identityToken->1hge4qw8wh4gndjoawud4|b81be4]-AdminTaskTimer] DEBUG com.mchange.v2.async.ThreadPoolAsynchronousRunner - com.mchange.v2.async.ThreadPoolAsynchronousRunner@b66600: Adding task to queue -- com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@934847
[C3P0PooledConnectionPoolManager[identityToken->1hge4qw8wh4gndjoawud4|b81be4]-HelperThread-#0] DEBUG com.mchange.v2.resourcepool.BasicResourcePool - An exception occurred while acquiring a poolable resource. Will retry.
java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getDriver(DriverManager.java:264)
at com.mchange.v2.c3p0.DriverManagerDataSource.driver(DriverManagerDataSource.java:240)
at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:146)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:195)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:184)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:200)
at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1086)
at com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1073)
at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:44)
at com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(BasicResourcePool.java:1810)
at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:648)
获取异常 java.sql.SQLException:没有合适的驱动程序。
当我查看源代码时,它正在寻找属性“hibernate.connection.driver_class”。我已经在“javax.persistence.jdbc.driver”中提到了驱动程序类。
我认为我没有正确配置连接池。该应用程序使用的是hibernate 4.1.11(没有spring),JPA2,Postgresql 9.1。没有hibernate.cfg.xml。
问题
hibernate.connection.driver_class
属性,连接池和JPA连接创建的连接是相同还是不同?注意
<!-- Connection Pooling -->
之后的行,则会运行。但是如果我在<!-- Connection Pooling -->
之后为连接池添加行,我就会遇到此异常。答案 0 :(得分:0)
回到过去,您必须使用Class.forName(org.postgresql.Driver.class)
构造加载相应的驱动程序类。使用JDBC 4.0驱动程序不再需要 - 但您可以尝试一下。
或者,尝试使用-Djdbc.drivers=org.postgresql.Driver
启动应用程序,它与Class.forName
代码段几乎相同,但不要求您对驱动程序类进行硬编码。希望它有所帮助。
答案 1 :(得分:0)
从答案
https://stackoverflow.com/a/10899364/112500
我能够解决问题。
将此行添加到c3p0-config.xml
之后<property name="driverClass">org.postgresql.Driver</property>