我经历了很多类似这个问题的论坛。但我仍然无法得到解决方案。 以下是我的应用程序jar版本和完整堆栈跟踪详细信息的简要说明。如果有人解决这个问题。请帮帮我。
Spring: <org.springframework.version>4.0.5.RELEASE</org.springframework.version>
Hibernate: <hibernate.version>4.3.5.Final</hibernate.version>
JPA:spring-orm-4.0.5.RELEASE.jar
C3P0:com.springsource.com.mchange.v2.c3p0-0.9.1
---------------------------------------------------------------------------------------------
application-context.xml
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass">
<value>#{cpadbProps['cpa.jdbc.driverClassName']}</value>
</property>
<property name="jdbcUrl">
<value>#{cpadbProps['cpa.jdbc.url']}</value>
</property>
<property name="user">
<value>#{cpadbProps['cpa.jdbc.username']}</value>
</property>
<property name="password">
<value>#{cpadbProps['cpa.jdbc.password']}</value>
</property>
<property name="dataSourceName" value="#{cpadbProps['cpa.applicationName']}" />
<property name="initialPoolSize"><value>#{dbProps['hibernate.c3p0.initialPoolSize']}</value></property>
<property name="minPoolSize"><value>#{dbProps['hibernate.c3p0.minPoolSize']}</value></property>
<property name="maxPoolSize"><value>#{dbProps['hibernate.c3p0.maxPoolSize']}</value></property>
<property name="acquireRetryAttempts"><value>#{dbProps['hibernate.c3p0.acquireRetryAttempts']}</value></property>
<property name="acquireIncrement"><value>#{dbProps['hibernate.c3p0.acquireIncrement']}</value></property>
<property name="idleConnectionTestPeriod"><value>#{dbProps['hibernate.c3p0.idleConnectionTestPeriod']}</value></property>
<property name="maxIdleTime"><value>#{dbProps['hibernate.c3p0.maxIdleTime']}</value></property>
<property name="maxConnectionAge"><value>#{dbProps['hibernate.c3p0.maxConnectionAge']}</value></property>
<property name="preferredTestQuery"><value>#{dbProps['hibernate.c3p0.preferredTestQuery']}</value></property>
<property name="testConnectionOnCheckin"><value>#{dbProps['hibernate.c3p0.testConnectionOnCheckin']}</value></property>
<property name="checkoutTimeout"><value>30000</value></property>
</bean>
<!-- ************ JPA configuration *********** -->
<bean id="cpaEntityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="database" value="MYSQL" />
</bean>
</property>
<property name="packagesToScan" value="com.causeway.pm.cpaintegration.transferobjects"></property>
<property name="loadTimeWeaver">
<bean
class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver" />
</property>
<property name="jpaProperties">
<map>
<entry key="hibernate.dialect" value="#{cpadbProps['cpa.hibernate.dialect']}" />
<entry key="hibernate.show_sql" value="#{dbProps['hibernate.show_sql']}" />
<entry key="hibernate.hbm2ddl.auto" value="#{dbProps['hibernate.hbm2ddl.auto']}" />
<entry key="hibernate.jdbc.batch_size" value="#{dbProps['hibernate.jdbc.batch_size']}" />
<entry key="hibernate.jdbc.fetch_size" value="#{dbProps['hibernate.jdbc.fetch_size']}" />
<entry key="hibernate.max_fetch_depth" value="#{dbProps['hibernate.max_fetch_depth']}" />
<entry key="hibernate.jdbc.use_scrollable_resultsets" value="true" />
<entry key="hibernate.default_batch_fetch_size" value="30" />
<entry key="hibernate.jdbc.batch_versioned_data" value="true" />
<entry key="hibernate.generate_statistics" value="true" />
<entry key="hibernate.cache" value="true" />
<entry key="hibernate.cache.use_second_level_cache" value="true" />
<entry key="hibernate.cache.use_query_cache" value="true" />
<entry key="hibernate.cache.provider_class" value="org.hibernate.cache.EhCacheProvider" />
<entry key="hibernate.cache.provider_configuration_file_resource_path"
value="classpath:conf/ehcache.xml" />
<entry key="hibernate.cache.region.factory_class"
value="org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory" />
</map>
</property>
</bean>
<bean id="cpaTransactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="cpaEntityManagerFactory" />
</bean>
<tx:annotation-driven mode="aspectj"
transaction-manager="cpaTransactionManager" />
---------------------------------------------------------------------------------------------------
dbProps.properties
hibernate.show_sql=true
hibernate.hbm2ddl.auto=no-create
hibernate.jdbc.batch_size=20
hibernate.jdbc.fetch_size=20
hibernate.max_fetch_depth=2
hibernate.c3p0.initialPoolSize=10
hibernate.c3p0.minPoolSize=1
hibernate.c3p0.maxPoolSize=25
hibernate.c3p0.acquireRetryAttempts=10
hibernate.c3p0.acquireIncrement=5
hibernate.c3p0.idleConnectionTestPeriod=10800
hibernate.c3p0.preferredTestQuery=SELECT 1;
hibernate.c3p0.testConnectionOnCheckin=false
hibernate.c3p0.maxConnectionAge=14400
hibernate.c3p0.maxIdleTime=21600
cpadbProps.properties
cpa.hibernate.dialect=org.hibernate.dialect.SQLServer2008Dialect
cpa.jdbc.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
cpa.jdbc.url=jdbc:sqlserver://xxx-xxx:1433;databaseName=xxx
--------------------Error Stack Trace------------\\
<pre> <code>
2014-09-02 13:18:34,741 ERROR | http-bio-8080-exec-2 | com.causeway.pm.web.interceptor.RestExceptionProcessor | Could not open JPA EntityManager for transaction; nested exception is javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Could not open connection
com.causeway.ctl.common.service.exception.ServiceException: Could not open JPA EntityManager for transaction; nested exception is javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Could not open connection
at com.causeway.pm.cpaintegration.service.CpaServiceImpl.listContracts(CpaServiceImpl.java:62) ~[cpa-integration-1.0.jar:na]
at com.causeway.pm.impl.service.ProjectServiceImpl.listCpaProjects(ProjectServiceImpl.java:53) ~[pm-impl-1.0.jar:na]
at com.causeway.pm.web.controller.ProjectController.listCpaProjects(ProjectController.java:67) ~[ProjectController.class:na]
at sun.reflect.GeneratedMethodAccessor98.invoke(Unknown Source) ~[na:na]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.7.0_67]
at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.7.0_67]
at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215) ~[spring-web-4.0.5.RELEASE.jar:4.0.5.RELEASE]
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132) ~[spring-web-4.0.5.RELEASE.jar:4.0.5.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104) ~[spring-webmvc-4.0.5.RELEASE.jar:4.0.5.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:749) ~[spring-webmvc-4.0.5.RELEASE.jar:4.0.5.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:689) ~[spring-webmvc-4.0.5.RELEASE.jar:4.0.5.RELEASE]
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83) ~[spring-webmvc-4.0.5.RELEASE.jar:4.0.5.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:938) ~[spring-webmvc-4.0.5.RELEASE.jar:4.0.5.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:870) ~[spring-webmvc-4.0.5.RELEASE.jar:4.0.5.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961) [spring-webmvc-4.0.5.RELEASE.jar:4.0.5.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852) [spring-webmvc-4.0.5.RELEASE.jar:4.0.5.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621) [servlet-api.jar:na]
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837) [spring-webmvc-4.0.5.RELEASE.jar:4.0.5.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728) [servlet-api.jar:na]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305) [catalina.jar:7.0.40]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) [catalina.jar:7.0.40]
at com.causeway.ctl.security.ResponseHeaderFilter.doFilter(ResponseHeaderFilter.java:37) [ctl-security-1.0.jar:na]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) [catalina.jar:7.0.40]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) [catalina.jar:7.0.40]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222) [catalina.jar:7.0.40]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123) [catalina.jar:7.0.40]
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472) [catalina.jar:7.0.40]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171) [catalina.jar:7.0.40]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99) [catalina.jar:7.0.40]
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953) [catalina.jar:7.0.40]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) [catalina.jar:7.0.40]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) [catalina.jar:7.0.40]
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1008) [tomcat-coyote.jar:7.0.40]
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589) [tomcat-coyote.jar:7.0.40]
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310) [tomcat-coyote.jar:7.0.40]
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [na:1.7.0_67]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [na:1.7.0_67]
at java.lang.Thread.run(Unknown Source) [na:1.7.0_67]
Caused by: org.springframework.transaction.CannotCreateTransactionException: Could not open JPA EntityManager for transaction; nested exception is javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Could not open connection
at org.springframework.orm.jpa.JpaTransactionManager.doBegin(JpaTransactionManager.java:430) ~[spring-orm-4.0.5.RELEASE.jar:4.0.5.RELEASE]
at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:373) ~[spring-tx-4.0.5.RELEASE.jar:4.0.5.RELEASE]
at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:420) ~[spring-tx-4.0.5.RELEASE.jar:4.0.5.RELEASE]
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:257) ~[spring-tx-4.0.5.RELEASE.jar:4.0.5.RELEASE]
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:95) ~[spring-tx-4.0.5.RELEASE.jar:4.0.5.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.0.5.RELEASE.jar:4.0.5.RELEASE]
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136) ~[spring-tx-4.0.5.RELEASE.jar:4.0.5.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.0.5.RELEASE.jar:4.0.5.RELEASE]
at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodIntercceptor.invoke(CrudMethodMetadataPostProcessor.java:111) ~[spring-data-jpa-1.6.0.RELEASE.jar:na]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.0.5.RELEASE.jar:4.0.5.RELEASE]
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) ~[spring-aop-4.0.5.RELEASE.jar:4.0.5.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.0.5.RELEASE.jar:4.0.5.RELEASE]
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207) ~[spring-aop-4.0.5.RELEASE.jar:4.0.5.RELEASE]
at com.sun.proxy.$Proxy63.findAll(Unknown Source) ~[na:na]
at com.causeway.pm.cpaintegration.service.CpaServiceImpl.listContracts(CpaServiceImpl.java:57) ~[cpa-integration-1.0.jar:na]
... 37 common frames omitted
Caused by: javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Could not open connection
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1387) ~[hibernate-entitymanager-4.2.12.Final.jar:4.2.12.Final]
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1310) ~[hibernate-entitymanager-4.2.12.Final.jar:4.2.12.Final]
at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:1397) ~[hibernate-entitymanager-4.2.12.Final.jar:4.2.12.Final]
at org.hibernate.ejb.TransactionImpl.begin(TransactionImpl.java:62) ~[hibernate-entitymanager-4.2.12.Final.jar:4.2.12.Final]
at org.springframework.orm.jpa.DefaultJpaDialect.beginTransaction(DefaultJpaDialect.java:67) ~[spring-orm-4.0.5.RELEASE.jar:4.0.5.RELEASE]
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.beginTransaction(HibernateJpaDialect.java:110) ~[spring-orm-4.0.5.RELEASE.jar:4.0.5.RELEASE]
at org.springframework.orm.jpa.JpaTransactionManager.doBegin(JpaTransactionManager.java:380) ~[spring-orm-4.0.5.RELEASE.jar:4.0.5.RELEASE]
... 51 common frames omitted
Caused by: org.hibernate.exception.GenericJDBCException: Could not open connection
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:54) ~[hibernate-core-4.2.12.Final.jar:4.2.12.Final]
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:124) ~[hibernate-core-4.2.12.Final.jar:4.2.12.Final]
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:109) ~[hibernate-core-4.2.12.Final.jar:4.2.12.Final]
at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.obtainConnection(LogicalConnectionImpl.java:221) ~[hibernate-core-4.2.12.Final.jar:4.2.12.Final]
at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.getConnection(LogicalConnectionImpl.java:157) ~[hibernate-core-4.2.12.Final.jar:4.2.12.Final]
at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.doBegin(JdbcTransaction.java:67) ~[hibernate-core-4.2.12.Final.jar:4.2.12.Final]
at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.begin(AbstractTransactionImpl.java:160) ~[hibernate-core-4.2.12.Final.jar:4.2.12.Final]
at org.hibernate.internal.SessionImpl.beginTransaction(SessionImpl.java:1351) ~[hibernate-core-4.2.12.Final.jar:4.2.12.Final]
at org.hibernate.ejb.TransactionImpl.begin(TransactionImpl.java:59) ~[hibernate-entitymanager-4.2.12.Final.jar:4.2.12.Final]
... 54 common frames omitted
Caused by: java.sql.SQLException: Connections could not be acquired from the underlying database!
at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:106) ~[com.springsource.com.mchange.v2.c3p0-0.9.1.jar:0.9.1]
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:529) ~[com.springsource.com.mchange.v2.c3p0-0.9.1.jar:0.9.1]
at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:128) ~[com.springsource.com.mchange.v2.c3p0-0.9.1.jar:0.9.1]
at org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider.getConnection(InjectedDataSourceConnectionProvider.java:70) ~[hibernate-entitymanager-4.2.12.Final.jar:4.2.12.Final]
at org.hibernate.internal.AbstractSessionImpl$NonContextualJdbcConnectionAccess.obtainConnection(AbstractSessionImpl.java:301) ~[hibernate-core-4.2.12.Final.jar:4.2.12.Final]
at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.obtainConnection(LogicalConnectionImpl.java:214) ~[hibernate-core-4.2.12.Final.jar:4.2.12.Final]
... 59 common frames omitted
Caused by: com.mchange.v2.resourcepool.CannotAcquireResourceException: A ResourcePool could not acquire a resource from its primary factory or source.
- List item
at com.mchange.v2.resourcepool.BasicResourcePool.awaitAvailable(BasicResourcePool.java:1319) ~[com.springsource.com.mchange.v2.c3p0-0.9.1.jar:0.9.1]
at com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:557) ~[com.springsource.com.mchange.v2.c3p0-0.9.1.jar:0.9.1]
at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:477) ~[com.springsource.com.mchange.v2.c3p0-0.9.1.jar:0.9.1]
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:525) ~[com.springsource.com.mchange.v2.c3p0-0.9.1.jar:0.9.1]
... 63 common frames omitted