在Hibernate中使用c3p0,配置如下

  1. <!-- c3p0连接池 --> 
  2.         <property name="connection.provider_class"> 
  3.             org.hibernate.conection.C3P0ConnectionProvider  
  4.         </property> 
  5.         <property name="c3p0.min_size">5</property> 
  6.         <property name="c3p0.max_size">20</property> 
  7.         <property name="c3p0.timeout">3600</property> 
  8.         <property name="c3p0.max_statements">10</property> 

本地运行java程序没有报错,部署到tomcat以后运行出现以下异常:

  1. java.lang.reflect.InvocationTargetException  
  2.     sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  
  3.     sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)  
  4.     sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)  
  5.     java.lang.reflect.Method.invoke(Method.java:597)  
  6.     com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:452)  
  7.     com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:291)  
  8.     com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:254)  
  9.     com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:176)  
  10.     com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)  
  11.     com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)  
  12.     com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:263)  
  13.     org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)  
  14.     com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)  
  15.     com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)  
  16.     com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:133)  
  17.     com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)  
  18.     com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:207)  
  19.     com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)  
  20.     com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)  
  21. 以下省略 


 

解决办法:

把配置修改成下面的就可以了

  1. <!-- c3p0连接池 --> 
  2.         <property name="org.hibernate.connection.C3P0ConnectionProvider"> 
  3.             org.hibernate.conection.C3P0ConnectionProvider  
  4.         </property> 
  5.         <property name="c3p0.min_size">5</property> 
  6.         <property name="c3p0.max_size">20</property> 
  7.         <property name="c3p0.timeout">3600</property> 
  8.         <property name="c3p0.max_statements">10</property>