java Hibernate读取和更新大型数据
我需要从表中读取大数据并更新它
什么是最好的解决方案
我正在使用流,但它有问题
Caused by: java.sql.SQLException: Streaming result set com.mysql.cj.protocol.a.result.ResultsetRowsStreaming@3ea407e4 is still active.
在给定连接上打开并使用任何流结果集时,不得发出任何语句。在尝试更多查询之前,请确保已对任何活动流结果集调用了.close()
。
我的代码如下:
Stream<UserNotificationDTO> dtoStream = userNotificationRepo.fetchAllUnreadByUserId(userId);
dtoStream.forEach(userNotifyDTO -> {
userNotifyDTO.setOpened(true);
userNotificationRepo.save(userNotifyDTO);
});
# 1 楼答案
这是一个mysql限制。在遍历结果时不能发出其他查询:
资料来源:http://openjpa.apache.org/builds/2.4.2/apache-openjpa/docs/dbsupport_mysql.html
# 2 楼答案
它可以是以下两种情况之一: