SSH整合遇到的坑

1:配置文件有错,c3p0连接池初始化不了。报的错误为:如下。这时候要检查你的hibernate.cfg.xml文件是否配置错误,着重检查四大必须参数。看是否有错,或者数据库是否存在于数据库中。我的错误是忘记创建数据库。

INFOC3P0Registry: 216-Initializingc3p0-0.9.2.1[
    built20-March-201310: 47: 27+0000;debug?true;trace: 10
]09: 38: 13,
913INFOAbstractPoolBackedDataSource: 522-Initializingc3p0pool...com.mchange.v2.c3p0.PoolBackedDataSource@accd668b[
    connectionPoolDataSource->com.mchange.v2.c3p0.WrapperConnectionPoolDataSource@d8a61d79[
        acquireIncrement->3,
        acquireRetryAttempts->30,
        acquireRetryDelay->1000,
        autoCommitOnClose->false,
        automaticTestTable->null,
        breakAfterAcquireFailure->false,
        checkoutTimeout->0,
        connectionCustomizerClassName->null,
        connectionTesterClassName->com.mchange.v2.c3p0.impl.DefaultConnectionTester,
        debugUnreturnedConnectionStackTraces->false,
        factoryClassLocation->null,
        forceIgnoreUnresolvedTransactions->false,
        identityToken->1hgf4019u1amn1pv122ym90|cf50384,
        idleConnectionTestPeriod->0,
        initialPoolSize->3,
        maxAdministrativeTaskTime->0,
        maxConnectionAge->0,
        maxIdleTime->0,
        maxIdleTimeExcessConnections->0,
        maxPoolSize->15,
        maxStatements->0,
        maxStatementsPerConnection->0,
        minPoolSize->3,
        nestedDataSource->com.mchange.v2.c3p0.DriverManagerDataSource@9d084096[
            description->null,
            driverClass->null,
            factoryClassLocation->null,
            identityToken->1hgf4019u1amn1pv122ym90|366b9f68,
            jdbcUrl->jdbc: mysql: ///day38,
            properties->{
                user=******,
                password=******
            }
        ],
        preferredTestQuery->null,
        propertyCycle->0,
        statementCacheNumDeferredCloseThreads->0,
        testConnectionOnCheckin->false,
        testConnectionOnCheckout->false,
        unreturnedConnectionTimeout->0,
        usesTraditionalReflectiveProxies->false;userOverrides: {
            
        }
    ],
    dataSourceName->null,
    factoryClassLocation->null,
    identityToken->1hgf4019u1amn1pv122ym90|3f9a962c,
    numHelperThreads->3
]
SSH整合遇到的坑_第1张图片
2:在业务层ServiceImpl中是否开启事物。我的报错为在事物中是只处于只读模式,不能写入数据库。read-only。排查错误为业务层ServiceImpl中忘记开启事物的注解。
09:45:04,485 ERROR DefaultDispatcherErrorHandler:42 - Exception occurred during processing request: Write operations are not allowed in read-only mode (FlushMode.MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction definition.
org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode (FlushMode.MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction definition.
	at org.springframework.orm.hibernate5.HibernateTemplate.checkWriteOperationAllowed(HibernateTemplate.java:1126)
	at org.springframework.orm.hibernate5.HibernateTemplate$12.doInHibernate(HibernateTemplate.java:619)
	at org.springframework.orm.hibernate5.HibernateTemplate$12.doInHibernate(HibernateTemplate.java:616)
	at org.springframework.orm.hibernate5.HibernateTemplate.doExecute(HibernateTemplate.java:341)
	at org.springframework.orm.hibernate5.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:309)
	at org.springframework.orm.hibernate5.HibernateTemplate.save(HibernateTemplate.java:616)
	at com.day38_ssh1.dao.CustomerDaoImpl.save(CustomerDaoImpl.java:25)
	at com.day38_ssh1.service.CustomerServiceImpl.save(CustomerServiceImpl.java:24)
	at com.day38_ssh1.web.action.CustomerAction.add(CustomerAction.java:45)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:606)
	at ognl.OgnlRuntime.invokeMethod(OgnlRuntime.java:870)
	at ognl.OgnlRuntime.callAppropriateMethod(OgnlRuntime.java:1293)
	at ognl.ObjectMethodAccessor.callMethod(ObjectMethodAccessor.java:68)
	at com.opensymphony.xwork2.ognl.accessor.XWorkMethodAccessor.callMethodWithDebugInfo(XWorkMethodAccessor.java:117)
	at com.opensymphony.xwork2.ognl.accessor.XWorkMethodAccessor.callMethod(XWorkMethodAccessor.java:108)
	at ognl.OgnlRuntime.callMethod(OgnlRuntime.java:1369)
	at ognl.ASTMethod.getValueBody(ASTMethod.java:90)
	at ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:212)
	at ognl.SimpleNode.getValue(SimpleNode.java:258)
	at ognl.Ognl.getValue(Ognl.java:494)
	at ognl.Ognl.getValue(Ognl.java:458)
	at com.opensymphony.xwork2.ognl.OgnlUtil$2.execute(OgnlUtil.java:309)
	at com.opensymphony.xwork2.ognl.OgnlUtil.compileAndExecute(OgnlUtil.java:340)
	at com.opensymphony.xwork2.ognl.OgnlUtil.getValue(OgnlUtil.java:307)
	at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:423)
	at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:287)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:250)
	at org.apache.struts2.interceptor.DeprecationInterceptor.intercept(DeprecationInterceptor.java:41)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
	at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:256)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
	at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:167)
	at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
	at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:265)
	at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:76)
	at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
	at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:138)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
	at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:229)
	at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
	at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:229)
	at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
	at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:191)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
	at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:73)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
	at org.apache.struts2.interceptor.DateTextFieldInterceptor.intercept(DateTextFieldInterceptor.java:125)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
	at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:91)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
	at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:253)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
	at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
	at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
	at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:145)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
	at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:171)
	at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
	at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:139)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
	at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
	at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:193)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
	at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:189)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
	at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54)
	at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:564)
	at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:81)
	at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:99)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
	at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:315)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
	at java.lang.Thread.run(Thread.java:745)
SSH整合遇到的坑_第2张图片
3:Jar包冲突,删除低版本的Jar包。整合SSH时,Hibernate和Struts2中都有Javassist的Jar包,于是在懒加载是遇到错误,解决办法,查看Struts2和Hibernate的Jar哪个版本低删除哪个。
SSH整合遇到的坑_第3张图片
4:延迟加载时,Session过早关闭,导致延迟加载时查询信息失败。在web.xml中编写如下配置文件,一定要在Struts的前端控制器前面配置。即可解决。
 
  
  	openSessionInViewFilter
  	org.springframework.orm.hibernate5.support.OpenSessionInViewFilter
  
  
  	openSessionInViewFilter
  	/*
  
SSH整合遇到的坑_第4张图片
5:Could not get constructor for org.hibernate.persister.entity.SingleTableEntityPersister;
在刚开启tomcat服务器加载SSH整合的项目时,登录项目首页报404错误,控制台输出的是上面的错误,根据控制台我的排查错误是因为我的JavaBean属性字段与映射资源文件的配置名字有出入,修改后还报这个错误是因为我修改完在生成set和get方法时,奇迹般竟然只选了set方法。
6: java.lang.IllegalArgumentException: id to load is required for loading解决方法,最后排查错误的地方就是在做删除时没有取到值造成的,我这里是因为拼错字母。注意花横线的地方要仔细检查。

7:下面这段错误是我在整合SSH修改时遇到的,一对多的多中,遇到这个错误,肯定是在修改时没有把主键值传回去,主键为null造成的。所以一定要检查主键,错误就可以排除。

HTTP Status 500 - The given object has a null identifier: com.crm_ssh.domain.Linkman; nested exception is org.hibernate.TransientObjectException: The given object has a null identifier: com.crm_ssh.domain.Linkman

8:Unable to instantiate Action, defined for in namespace '/':这个是由于Spring来管理Action,在Spring配置的Action的id和Struts配置的Action的class没有对应,所以就会报这个错误。


你可能感兴趣的:(SSH整合)