面临与休眠“ javax.persistence.TransactionRequiredException”

时间:2018-07-26 07:04:10

标签: java hibernate spring-mvc

嗨,当我尝试在服务器上成功部署我的WAR文件时,我可以成功部署,但是之后我的应用程序在服务器上正常工作了

  

javax.persistence.TransactionRequiredException:没有事务在   进步   org.hibernate.internal.SessionImpl.checkTransactionNeeded(SessionImpl.java:3466)     在org.hibernate.internal.SessionImpl.doFlush(SessionImpl.java:1426)     在org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1422)     在com.mcd.aag.dao.impl.AAGDAOImpl.insertAAGForm(AAGDAOImpl.java:70)     在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)处   sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)     在   sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)     在java.lang.reflect.Method.invoke(Method.java:498)在   org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:338)     在   org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:197)     在   org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)     在   org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:294)     在   org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98)     在   org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)     在   org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)     在com.sun.proxy。$ Proxy62.insertAAGForm(未知来源)处   com.mcd.aag.service.impl.AAGServiceImpl.insertFormOne(AAGServiceImpl.java:68)     在   com.mcd.aag.controller.AAGApplicationController.updateAAGFormOne(AAGApplicationController.java:245)     在   com.mcd.aag.controller.AAGApplicationController.insertUpdateAAGFormOne(AAGApplicationController.java:166)     在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)处   sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)     在   sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)     在java.lang.reflect.Method.invoke(Method.java:498)在   org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:209)     在   org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136)     在   org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102)     在   org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:871)     在   org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:777)     在   org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)     在   org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:991)     在   org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:925)     在   org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:978)     在   org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:881)     在javax.servlet.http.HttpServlet.service(HttpServlet.java:707)在   org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:855)     在javax.servlet.http.HttpServlet.service(HttpServlet.java:790)处   io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)     在   io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)     在   io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)     在   org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)     在   io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)     在   io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)     在   io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)     在   io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)     在   io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)     在   io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)     在   io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)     在   io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)     在   io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)     在   io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)     在   io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)     在   org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)     在   io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)     在   io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)     在   io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:285)     在   io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:264)     在   io.undertow.servlet.handlers.ServletInitialHandler.access $ 000(ServletInitialHandler.java:81)     在   io.undertow.servlet.handlers.ServletInitialHandler $ 1.handleRequest(ServletInitialHandler.java:175)     在   io.undertow.server.Connectors.executeRootHandler(Connectors.java:202)     在   io.undertow.server.HttpServerExchange $ 1.run(HttpServerExchange.java:802)     在   java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)     在   java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:617)     在java.lang.Thread.run(Thread.java:745)

请帮助我最近5天坚持下去

1 个答案:

答案 0 :(得分:1)

尝试在您的方法上添加@Transactional

您应该将实体管理器介绍给事务管理器,以便在使用@Transactional注释函数时,它会从池中加载实例

<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    <property name="entityManagerFactory" ref="myEmf" />
</bean>
<tx:annotation-driven />

如果上述方法无效,请参考以下线程。

https://stackoverflow.com/a/28950767/6572971