I am trying to stream data from repository and write it to the servlet output stream. While streaming , am facing unable to read data error. I already have @Transactional annotation in place..
@Autowired
private MyRepository < Y > repository;
@Autowired
private Gson gson;
@Transactional(readOnly = true)
public long writeData(ServletOutputStream outputStream) {
JsonWriter writer = new JsonWriter(new OutputStreamWriter(outputStream, UTF_8));
int count = 0;
writer.beginArray();
try (Stream < T > stream = repository.findAll()) {
stream.forEach(e ->{
gson.toJson(e, e.getClass(), writer);
count++;
});
}
writer.endArray();
writer.flush();
writer.close();
}
Error:
org.hibernate.exception.GenericJDBCException: could not advance using next()