![](/img/trans.png)
[英]org.hibernate.AssertionFailure: possible non-threadsafe access to the session
[英]HibernateCursorItemReader gets non-threadsafe access to the session Error
@Component
@Scope("step")
public class MyReader implements ItemReader<MyDto>, InitializingBean{
private HibernateCursorItemReader<Object[]> reader;
@Autowired
private SessionFactory sessionFactory;
@Override
public void afterPropertiesSet() throws Exception{
reader = new HibernateCursorItemReader<>();
reader.setSessionFactory(sessionFactory);
reader.setUseStatelessSession(true);
reader.setQueryString(/*query*/);
//...
}
public MyDto read() throws Exception{
Object[] record = reader.read(); //exception here org.hibernate.AssertionFailure: possible non-threadsafe access to the session
}
}
当使用HibernateCursorItemReader
,我得到了org.hibernate.AssertionFailure: possible non-threadsafe access to the session
异常。
怎么解决?
我需要它来运行read()
以便我可以将结果转储到一个新的MyDto
对象中供编写者处理/写入。 作者有自己的db调用来获取其他细节。
正如Javadoc所说 , HibernateCursorItemReader
不是线程安全的 。 问题不在于您发布的课程,而在于您使用它的方式。 可能你是在多线程步骤中使用它,但你不能。 除了使用单线程步骤(显而易见)之外,安全的多线程解决方案是使用异步ItemProcessor / ItemWriter 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.