Quartz 调用 Job 时 org.hibernate.HibernateException: Could not obtain transaction-synchronized Session for current thread
[2019-12-25 16:44:21] [INFO] [org.jeecgframework.web.system.controller.core.LoginController:178] >>>>>>>>>>>>>>>>>>>>>>>>>> Login 用户登录成功,初始化Main首页用户信息 (Main 首页加载逻辑) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> [2019-12-25 16:44:21] [INFO] [org.jeecgframework.web.system.controller.core.LoginController:222] login 资源路径returnURL:null [2019-12-25 16:44:35] [INFO] [org.jeecgframework.web.system.controller.core.LoginController:178] >>>>>>>>>>>>>>>>>>>>>>>>>> Login 用户登录成功,初始化Main首页用户信息 (Main 首页加载逻辑) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> [2019-12-25 16:44:36] [INFO] [org.jeecgframework.web.system.controller.core.LoginController:222] login 资源路径returnURL:null [2019-12-25 16:45:03] [INFO] [org.jeecgframework.core.timer.DynamicTask:124] 停止任务-------TaskId:recycle_resource_to_invalid_sea-------Describe:每月1日2点1分0秒,资源回收至无效公海-----ClassName:com.jeecg.crm.util.task.RecycleLeadsToInvalidSeaTask [2019-12-25 16:45:42] [INFO] [org.jeecgframework.core.timer.DynamicTask:124] 开启任务-------TaskId:recycle_resource_to_invalid_sea-------Describe:每月1日2点1分0秒,资源回收至无效公海-----ClassName:com.jeecg.crm.util.task.RecycleLeadsToInvalidSeaTask [2019-12-25 16:45:42] [INFO] [org.jeecgframework.core.timer.DynamicTask:183] 立即生效开启任务成功,任务ID:-------TaskId:recycle_resource_to_invalid_sea-------Describe:每月1日2点1分0秒,资源回收至无效公海-----ClassName:com.jeecg.crm.util.task.RecycleLeadsToInvalidSeaTask [2019-12-25 16:45:59] [INFO] [org.quartz.plugins.history.LoggingJobHistoryPlugin:469] Job DEFAULT.40288a366f21ca2c016f2245383d0009 fired (by trigger DEFAULT.cron_40288a366f21ca2c016f2245383d0009) at: 16:45:59 12/25/2019 [2019-12-25 16:45:59] [INFO] [com.jeecg.crm.util.task.RecycleLeadsToInvalidSeaTask:32] ===================start=================== [2019-12-25 16:46:00] [ERROR] [org.jeecgframework.core.common.dao.impl.GenericBaseCommonDao:213] 保存实体异常 org.hibernate.HibernateException: Could not obtain transaction-synchronized Session for current thread at org.springframework.orm.hibernate4.SpringSessionContext.currentSession(SpringSessionContext.java:134) at org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:1024) at org.jeecgframework.core.common.dao.impl.GenericBaseCommonDao.getSession(GenericBaseCommonDao.java:88) at org.jeecgframework.core.common.dao.impl.GenericBaseCommonDao.save(GenericBaseCommonDao.java:206) at org.jeecgframework.core.common.service.impl.CommonServiceImpl.save(CommonServiceImpl.java:57) at com.jeecg.crm.service.impl.PublicSeaOperationRecordServiceImpl.save(PublicSeaOperationRecordServiceImpl.java:62) at com.jeecg.crm.service.impl.PublicSeaOperationRecordServiceImpl.saveByRecycle(PublicSeaOperationRecordServiceImpl.java:282) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:333) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207) at com.sun.proxy.$Proxy92.saveByRecycle(Unknown Source) at com.jeecg.crm.service.impl.RecycleRulesServiceImpl.doRecyle(RecycleRulesServiceImpl.java:189) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:333) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207) at com.sun.proxy.$Proxy117.doRecyle(Unknown Source) at com.jeecg.crm.util.task.RecycleLeadsToInvalidSeaTask.execute(RecycleLeadsToInvalidSeaTask.java:75) at org.quartz.core.JobRunShell.run(JobRunShell.java:202) at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573)
quartz org.hibernate.HibernateException: Could not obtain transaction-synchronized Session for curre - 国内版 Bing
https://cn.bing.com/search?q=quartz+org.hibernate.HibernateException%3A+Could+not+obtain+transaction-synchronized+Session+for+curre&qs=n&form=QBRE&sp=-1&pq=quartz+org.hibernate.hibernateexception%3A+could+not+obtain+transaction-synchronized+session+for+curre&sc=0-100&sk=&cvid=9E68C26AE2CD403AA5E1E5E2FFB6854C
java - QuartzJobBean could not obtain transaction-synchronized Session - Stack Overflow
https://stackoverflow.com/questions/45933942/quartzjobbean-could-not-obtain-transaction-synchronized-session
大神都来看看吧!!!-Could not obtain transaction-synchronized Session for current thread-CSDN论坛
https://bbs.csdn.net/topics/390971954
Hibernate4中使用getCurrentSession报Could not obtain transaction-synchronized Session for current thread_xdy3008的专栏-CSDN博客
https://blog.csdn.net/xdy3008/article/details/74332098
springMvc4+hibernate4的一个奇葩的网上众说纷纭的错误 - 云+社区 - 腾讯云
https://cloud.tencent.com/developer/article/1096406
======================================
org.hibernate.HibernateException: Could not obtain transaction-synchronized Session for current thread - 国内版 Bing
https://cn.bing.com/search?FORM=U227DF&PC=U227&q=org.hibernate.HibernateException%3A+Could+not+obtain+transaction-synchronized+Session+for+current+thread
关于Hibernate Could not obtain transaction-synchronized Session for current thread - 郑松林 - 博客园
https://www.cnblogs.com/zhengsonglin/articles/8159117.html
多线程出现HibernateException: Could not obtain transaction-synchronized Session for current thread_linchao302的专栏-CSDN博客
https://blog.csdn.net/linchao302/article/details/77838769
springmvc+spring4+hibernate4整合Could not obtain transaction-synchronized Session for current thread_baidu_28283827的博客-CSDN博客
https://blog.csdn.net/baidu_28283827/article/details/52748125
Could not obtain transaction-synchronized Session for current thread_session,hibernate_CodeNote-CSDN博客
https://blog.csdn.net/zuoyixiao/article/details/52278805
org.hibernate.HibernateException: Could not obtain transaction-synchronized Session for current thre_Hibernate,Spring,Struts2_游海东的技术专栏-CSDN博客
https://blog.csdn.net/you23hai45/article/details/56678094
=========================================
解决方案:
先检查spring的xml中配置的 transaction manager是否正确。
BugFix:方法未封装入*ServiceImpl类,导致org.hibernate.HibernateException: Could not obtain transaction-synchronized Session for current thread。
附加问题:
BugFix:给Job设定非并发执行模式@DisallowConcurrentExecution,防止并发执行冲突。@PersistJobDataAfterExecution。参考Quartz的statefulJob实现类。
Improvement:Job的继承类用@Component注解更合适。