[英]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
}
}
When using the HibernateCursorItemReader
, I got the org.hibernate.AssertionFailure: possible non-threadsafe access to the session
Exception. 当使用
HibernateCursorItemReader
,我得到了org.hibernate.AssertionFailure: possible non-threadsafe access to the session
异常。
How to fix it? 怎么解决?
I need it to run the read()
so that I can dump the results into a new MyDto
Object for the writer to process/write. 我需要它来运行
read()
以便我可以将结果转储到一个新的MyDto
对象中供编写者处理/写入。 The writer has its own db calls to get other details too. 作者有自己的db调用来获取其他细节。
As Javadoc says , HibernateCursorItemReader
is not thread-safe . 正如Javadoc所说 ,
HibernateCursorItemReader
不是线程安全的 。 The problem is not in the class you have posted but in the way you are using it. 问题不在于您发布的课程,而在于您使用它的方式。 Probably you are using it in a multithreaded step but you can't.
可能你是在多线程步骤中使用它,但你不能。 Besides using a single-threaded step (obvious), a safe multithreaded solution is to use async ItemProcessor/ItemWriter .
除了使用单线程步骤(显而易见)之外,安全的多线程解决方案是使用异步ItemProcessor / ItemWriter 。
See also https://stackoverflow.com/a/28724199/685806 另请参见https://stackoverflow.com/a/28724199/685806
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.