问题描述
type Exception report message description The server encountered an internal error () that prevented it from fulfilling this request. exception java.lang.RuntimeException: tx.rollbacd() throw exception = org.hibernate.TransactionException: JDBC rollback failed com.soc.hibernate.BaseDaoHibernate.find2(BaseDaoHibernate.java:344) com.soc.index.action.IndexAction.initIndex(IndexAction.java:248)sun.reflect.GeneratedMethodAccessor228.invoke(Unknown Source) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) java.lang.reflect.Method.invoke(Method.java:597) com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:453) com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:292) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:255) org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:256) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249) com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept (DefaultWorkflowInterceptor.java:176) com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249) com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:265) org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept (AnnotationValidationInterceptor.java:68) com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249) com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept (ConversionErrorInterceptor.java:138) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249) com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:211) com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249) com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:211) com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249) com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept (StaticParametersInterceptor.java:190) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249) org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249) org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:90) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249) org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:243) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249) com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249) com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept (ScopedModelDrivenInterceptor.java:141) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249) com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:145) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249) com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:171) com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249) com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:176) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249) org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249) com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:192) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249) com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept (ExceptionMappingInterceptor.java:187) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249) org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54) org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:511) org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77) org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter (StrutsPrepareAndExecuteFilter.java:91) com.soc.filter.CharsetFilter.doFilter(CharsetFilter.java:23) com.soc.filter.EncodingFilter.doFilter(EncodingFilter.java:23) java action 代码: 248行片段: /** * @return * chang * 初始化首页 */public String initIndex(){//政府咨询List<D0001> list = (List<D0001>) baseDao.find2(" from D0001 d", 0, 8, "d.d0007=11 order by d.d0008 desc,d.d0004 desc").get("result");request.setAttribute("zfzxList", changeTitle(list));request.setAttribute("zfzxImg", list.get(0));//热点咨询List<D0001> listRdzt = (List<D0001>) baseDao.find2(" from D0001 d", 0, 5, "d.d0007=12 order by d.d0008 desc,d.d0004 desc").get("result");request.setAttribute("rdztList", changeTitle2(listRdzt));request.setAttribute("rdztImg", listRdzt.get(0));//需求任务List<D0008> listxuqiu = (List<D0008>) baseDao.find2(" from D0008 d", 0, 5, "1 = 1 order by d.d0001 desc").get("result");request.setAttribute("listxuqiu", changeTitle8(listxuqiu));request.setAttribute("listxuqiuImg", listxuqiu.get(0));//维权援助List<D0009> listWqyz = (List<D0009>) baseDao.find2(" from D0009 d", 0, 5, "1=1 order by d.d0001 desc").get("result");request.setAttribute("wqyzList", changeTitle9(listWqyz));request.setAttribute("wqyzImg", listWqyz.get(0));//政策信息List<D0001> listZfxx = (List<D0001>) baseDao.find2(" from D0001 d", 0, 5, "d.d0007=14 order by d.d0008 desc,d.d0004 desc").get("result");request.setAttribute("ZfxxList", changeTitle2(listZfxx));request.setAttribute("ZfxxImg", listZfxx.get(0));//转化成功案例List<D0001> listZhcgal = (List<D0001>) baseDao.find2(" from D0001 d", 0, 5, "d.d0007=15 order by d.d0008 desc,d.d0004 desc").get("result");request.setAttribute("listZhcgal", changeTitle2(listZhcgal));request.setAttribute("listZhcgalImg", listZhcgal.get(0));//发明创新指导List<D0001> listFmcxzd = (List<D0001>) baseDao.find2(" from D0001 d", 0, 5, "d.d0007=16 order by d.d0008 desc,d.d0004 desc").get("result");request.setAttribute("listFmcxzd", changeTitle2(listFmcxzd));request.setAttribute("listFmcxzdImg", listFmcxzd.get(0));//院校科研团队List<D0001> listYxkytd = (List<D0001>) baseDao.find2(" from D0001 d", 0, 5, "d.d0007=17 order by d.d0008 desc,d.d0004 desc").get("result");request.setAttribute("listYxkytd", changeTitle2(listYxkytd));request.setAttribute("listYxkytdImg", listYxkytd.get(0)); 网站运行2--3天就会出现这种情况,请问是什么问题,求大神解救。谢谢啦。
解决方案
是你的事物回滚失败了你的hibernate链接是否加入c3p0连接池之类的出现这个问题的原因首先, 你的代码是从数据库读取用户信息, 不是写入数据. 所以不能使用事务和rollback方法.第二, 当你更新和插入一条记录到数据库, 使用事务的时候, 关闭数据库的自动提交. 检查你的连接池是否正常.第三, 当你有一个错误, 一定要关闭你的Hibernate连接. 当你捕获一个异常, 使用finally关闭hibernate Session或者数据库连接.另外, 可能连接池已经用完.
解决方案二:
我觉得是你某个数据库操作阻塞了进程,看看那些语句查询时间比较长,优化一下,加个索引啥的。
解决方案三:
这个样子,我以前也是遇到这个问题的,那时候我用的是hibernate自带的数据连接池,网站每隔8小时就死掉,然后报类似的错误,后来我通过1天的查阅资料总结了这种我称之为8小时问题的问题:hibernate自带的数据源会在创建好数据连接池以后就不再管这个连接是否有效,而是天真的任务只要创建,那么就会一直有效。然而吝啬的mysql(当时我用的是mysql),却会在发现这个连接如果8小时没有使用就会自行断掉,但hibernate自带的连接池不知道,而去直接使用这个连接,这样就会异常了。你用的c3p0数据源的话也要配置一下每次使用连接之前去检查一下连接的有效性: <!-- 每次都验证连接是否可用 这里就可以啦!--> <property name="hibernate.c3p0.validate">true</property> 另外,你配置c3p0后得告诉hibernate,否则他还会用自己自带的数据源的:<!—很重要,hibernate会根据这个属性来确定使用c3p0数据源--> <property name="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>ps:如果你的网站总有人访问的话,其实也就不用愁8小时问题了,哈哈·····