【发布时间】:2020-11-19 09:09:15
【问题描述】:
我正在尝试从存储库流式传输数据并将其写入 servlet 输出流。流式传输时,我面临无法读取数据错误。我已经有了@Transactional 注释..
@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();
}
错误:
org.hibernate.exception.GenericJDBCException: could not advance using next()
【问题讨论】:
标签: spring-boot rest jpa spring-data-jpa java-stream