![](/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.