事务影响懒加载 no session or session was closed

公司有个跑批,原先的事务配置删了,导致访问数据库拿到数据后就关了session

众所周知,懒加载就是用到该数据时才去数据库加载,但session都关了,还谈何加载,并报了下面这个错

 

2019-05-28 09:45:00,191 cn.com.sinosoft.job.StaffWelfareInsuredJob.doJob(StaffWelfareInsuredJob.java:98) INFO   -员工福利承保任务:进行承保操作。订单号为:B0001552097
2019-05-28 09:45:00,191 org.hibernate.LazyInitializationException.<init>(LazyInitializationException.java:42) ERROR  -failed to lazily initialize a collection of role: cn.com.sinosoft.iecs.online.domain.sale.GeStaffPolicy.geStaffInfos, no session or session was closed
org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: cn.com.sinosoft.iecs.online.domain.sale.GeStaffPolicy.geStaffInfos, no session or session was closed
	at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:383)
	at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:375)
	at org.hibernate.collection.AbstractPersistentCollection.readSize(AbstractPersistentCollection.java:122)
	at org.hibernate.collection.PersistentBag.size(PersistentBag.java:248)
	at cn.com.sinosoft.iecs.online.sale.service.impl.StaffWelfareSaleServiceImpl.getStaffWelfareInfo(StaffWelfareSaleServiceImpl.java:96)
	at cn.com.sinosoft.job.StaffWelfareInsuredJob.doJob(StaffWelfareInsuredJob.java:99)
	at sun.reflect.GeneratedMethodAccessor12895.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.springframework.util.MethodInvoker.invoke(MethodInvoker.java:269)
	at cn.com.sinosoft.springframework.scheduling.quartz.BeanInvokingJobDetailFactoryBean$BeanInvokingJob.execute(BeanInvokingJobDetailFactoryBean.java:486)
	at org.quartz.core.JobRunShell.run(JobRunShell.java:223)
	at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:549)

加回事务配置后,session不再是用完就关,问题解决。

@Transactional(value="transactionManager",isolation=Isolation.READ_UNCOMMITTED)

 

转载于:https://my.oschina.net/u/2277088/blog/3056344

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值