Hibernate和ehCache配置的事务问题

时间:2015-02-25 22:31:23

标签: hibernate ehcache jta

在我的hibernate映射中,我将缓存使用情况视为只读

<class name="cdot.ctms.layer.services.dispatch.data.DispatchMapDTO"
        table="DISPATCH_MAP" mutable="false" optimistic-lock="version">
        <cache usage="read-only"/>

在我的ehCache.xml中,我将默认缓存设置为

<defaultCache
            maxEntriesLocalHeap="10000"
            eternal="false"
            timeToIdleSeconds="120"
            timeToLiveSeconds="120"
            diskSpoolBufferSizeMB="30"
            maxEntriesLocalDisk="10000000"
            diskExpiryThreadIntervalSeconds="120"
            memoryStoreEvictionPolicy="LRU"
            transactionalMode="xa_strict">
        <persistence strategy="localTempSwap"/>
    </defaultCache>

当我的对象选择默认缓存时,它会运行到事务回滚问题。

如果我为我所指的对象显式添加缓存,我不会遇到任何问题。

<cache 
        name="cdot.ctms.layer.services.dispatch.data.DispatchMapDTO" 
        maxEntriesLocalHeap="100" 
        eternal="false"
        timeToLiveSeconds="300">
        <persistence strategy="localTempSwap" />
    </cache>

我们有很多DTO在我们的应用程序中使用默认缓存。我是否必须在每个对象的ehCache.xml中为上面定义缓存?没有在hibernate手册中找到任何相关文档

http://docs.jboss.org/hibernate/orm/4.3/manual/en-US/html/ch20.html#performance-cache-readonly

有人可以解释我的配置有什么问题以及针对上述问题的最佳做法。

2015-02-24 10:05:27,390 ERROR(http-nio-127.0.0.1-8080-exec-6)[cdot.ctms.layer.web.fire.spring.AtmosphereHandlerExceptionResolver] ExceptionResolver错误是:JTA事务意外退回(可能是由于超时);嵌套异常是javax.transaction.RollbackException:无法提交:标记为回滚的事务 org.springframework.transaction.UnexpectedRollbackException:JTA事务意外回滚(可能是由于超时);嵌套异常是javax.transaction.RollbackException:无法提交:标记为回滚的事务     在org.springframework.transaction.jta.JtaTransactionManager.doCommit(JtaTransactionManager.java:1024)     在org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:757)     在org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:726)     在org.jencks.GeronimoPlatformTransactionManager.commit(GeronimoPlatformTransactionManager.java:76)     at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:521)     at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:291)     at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)     在org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)     在org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)     在com.sun.proxy。$ Proxy143.getDispatchMaps(未知来源)     在cdot.ctms.layer.delegate.controllers.DispatchController.getDispatchMaps(DispatchController.java:60)     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)     at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)     at java.lang.reflect.Method.invoke(Unknown Source)     at cdot.ctms.layer.delegate.facade.AnnotationDelegateController.executeInternal(AnnotationDelegateController.java:287)     at cdot.ctms.layer.delegate.facade.AnnotationDelegateController.processAction(AnnotationDelegateController.java:232)     在cdot.ctms.layer.web.controller.BaseWebController.processAction(BaseWebController.java:94)     at cdot.ctms.layer.web.dispatch.controller.DispatchController.findDispatchMapsUnderSection(DispatchController.java:82)     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)     at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)     at java.lang.reflect.Method.invoke(Unknown Source)     在org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)     在org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137)     在org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)     在org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:777)     在org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:706)     在org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)     在org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:943)     在org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877)     在org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)     在org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857)     在javax.servlet.http.HttpServlet.service(HttpServlet.java:618)     在org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)     在javax.servlet.http.HttpServlet.service(HttpServlet.java:725)     at org.atmosphere.util.AtmosphereFilterChain.doFilter(AtmosphereFilterChain.java:135)     at org.atmosphere.util.AtmosphereFilterChain.invokeFilterChain(AtmosphereFilterChain.java:96)     在org.atmosphere.handler.ReflectorServletProcessor $ FilterChainServletWrapper.service(ReflectorServletProcessor.java:317)     在org.atmosphere.handler.ReflectorServletProcessor.onRequest(ReflectorServletProcessor.java:160)     在org.atmosphere.cpr.AsynchronousProcessor.action(AsynchronousProcessor.java:205)     在org.atmosphere.cpr.AsynchronousProcessor.suspended(AsynchronousProcessor.java:104)     在org.atmosphere.container.Servlet30CometSupport.service(Servlet30CometSupport.java:66)     在org.atmosphere.cpr.AtmosphereFramework.doCometSupport(AtmosphereFramework.java:2079)     在org.atmosphere.cpr.AtmosphereServlet.doPost(AtmosphereServlet.java:211)     在org.atmosphere.cpr.AtmosphereServlet.doGet(AtmosphereServlet.java:197)     在javax.servlet.http.HttpServlet.service(HttpServlet.java:618)     在javax.servlet.http.HttpServlet.service(HttpServlet.java:725)     在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)     在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)     在org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)     在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)     在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)     在org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:330)     在org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118)     在org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84)     在org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:342)     在org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)     在org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:342)     在org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103)     在org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:342)     在org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)     在org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:342)     在org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:154)     在org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:342)     在org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)     在org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:342)     在org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:199)     在org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:342)     在org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:110)     在org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:342)     在cdot.web.filter.BaseWebRequestFilter.doFilter(BaseWebRequestFilter.java:75)     在org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:342)     在org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)     在org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:342)     在org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:50)     在org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)     在org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:342)     在org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192)     在org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)     在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)     在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)     在cdot.web.filter.BaseWebRequestFilter.doFilter(BaseWebRequestFilter.java:75)     在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)     在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)     在org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)     在org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)     在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)     在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)     在org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)     在org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)     在org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)     at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)     在org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)     at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)     在org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)     在org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:516)     在org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1086)     at org.apache.coyote.AbstractProtocol $ AbstractConnectionHandler.process(AbstractProtocol.java:659)     在org.apache.coyote.http11.Http11NioProtocol $ Http11ConnectionHandler.process(Http11NioProtocol.java:223)     在org.apache.tomcat.util.net.NioEndpoint $ SocketProcessor.doRun(NioEndpoint.java:1558)     在org.apache.tomcat.util.net.NioEndpoint $ SocketProcessor.run(NioEndpoint.java:1515)     at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)     at java.util.concurrent.ThreadPoolExecutor $ Worker.run(Unknown Source)     at org.apache.tomcat.util.threads.TaskThread $ WrappingRunnable.run(TaskThread.java:61)     在java.lang.Thread.run(未知来源) 引起:javax.transaction.RollbackException:无法提交:标记为回滚的事务     at org.apache.geronimo.transaction.manager.TransactionImpl.rollbackResourcesDuringCommit(TransactionImpl.java:670)     在org.apache.geronimo.transaction.manager.TransactionImpl.commit(TransactionImpl.java:322)     at org.apache.geronimo.transaction.manager.TransactionManagerImpl.commit(TransactionManagerImpl.java:252)     在org.springframework.transaction.jta.JtaTransactionManager.doCommit(JtaTransactionManager.java:1021)     ......还有105个

1 个答案:

答案 0 :(得分:0)

默认缓存配置与特定缓存配置之间存在差异。其中包括timeToLiveSeconds

如果您将默认缓存一次提升为300会怎样?