我知道这个错误已经发生,因为找不到更新对象的会话。当我使用下面的代码时,我得到“会话已经关闭”
@RequestMapping(value = Route.ediBillingLogCreate,method = {RequestMethod.POST, RequestMethod.GET})
public @ResponseBody String updateEdiBillingLog(@ModelAttribute("SearchEntityObject")EdiBilling404LogIiss ediBilling404LogIiss, BindingResult result, SessionStatus status, HttpServletRequest req, HttpServletResponse response)
{
BigDecimal id=ediBilling404LogIiss.getEdiBilling404LogUid();
if(id!=null && id.intValue()>0){
ediBillingLogService.updateupdateEdiBillingLog(ediBilling404LogIiss);
}
return "success";
}
但是当我在另一个控制器中使用类似的代码时,我没有收到此错误。 对于Eg:
@RequestMapping(value = Route.nvoccShipperForwarderSave)
public @ResponseBody
String saveForwarderDetails(@ModelAttribute("BlForwarderParties") BlHousePartiesIiss blHousePartiesIiss ,BindingResult result, SessionStatus status,@RequestParam String blNumber,@RequestParam long partyId, @RequestParam String blHouseUid) throws Exception {
if (result.hasErrors()) {
LOG.info("Errors" + result.toString());
}
Long id=null;
if(partyId==0){
id=nvoccBlHouseService.saveNewRecord(blHousePartiesIiss);
}
else
{
BlHousePartiesIiss idOld=nvoccBlHouseService.updatePartiesDetails(blHousePartiesIiss);
id=idOld.getHousePartyId();
}
return "success";
}
//的printStackTrace
SEVERE: [baseWebAppExceptionHandler] Response exception: org.springframework.orm.hibernate3.HibernateSystemException: Session was already closed!; nested exception is org.hibernate.SessionException: Session was already closed!
Mar 17, 2016 2:16:06 PM com.intellect.eShip.webapp.BaseControllerAdvice exceptionHandler
SEVERE: [baseWebAppExceptionHandler] Response getMessages: Session was already closed!; nested exception is org.hibernate.SessionException: Session was already closed!
Mar 17, 2016 2:16:06 PM com.intellect.eShip.webapp.BaseControllerAdvice exceptionHandler
SEVERE: [baseWebAppExceptionHandler] printStrackTrace: org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:690)
org.springframework.orm.hibernate3.HibernateTransactionManager.convertHibernateAccessException(HibernateTransactionManager.java:794)
org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:665)
org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:755)
org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:724)
org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:475)
org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:270)
org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:631)
com.intellect.eShip.service.ediOperations.EdiBillingLogService$$EnhancerByCGLIB$$40b36cb3.updateupdateEdiBillingLog(<generated>)
com.intellect.eShip.webapp.controller.ediOperations.EdiBillingLogController.updateEdiBillingLog(EdiBillingLogController.java:130)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:601)
org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219)
org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:745)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:686)
org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936)
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:838)
javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:947)
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1009)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
java.lang.Thread.run(Thread.java:722)
// updateEdiBillingLog
public void updateupdateEdiBillingLog(
EdiBilling404LogIiss ediBilling404LogIiss) {
try{
ediBillingLogDAO.update(ediBilling404LogIiss);
}
catch(Exception e)
{
e.printStackTrace();
}
}
Which in turn Calls below method
@Transactional
public T update(T object) {
sessionFactory.getCurrentSession().setFlushMode(FlushMode.AUTO);
sessionFactory.getCurrentSession().update(object);
try {
sessionFactory.getCurrentSession().flush();
} catch (HibernateException e) {
log.error(e.getMessage());
}
return object;
}
我想提醒您注意BlHousePartiesIiss和EdiBilling404LogIiss之间的区别。 BlHousePartiesIiss有一个主键。在EdiBilling404LogIiss中,键组合成为主键。
为什么行为存在差异?当我在两种情况下使用当前会话时。