@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.
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. The writer has its own db calls to get other details too.