【发布时间】:2020-01-19 22:41:49
【问题描述】:
在过去的项目中,我在服务功能中使用过以前版本的 Grails/Hibernate:
private void cleanGorm() {
def session = sessionFactory.currentSession
session.flush()
session.clear()
}
例如,在批量更新等长时间任务中,我使用过它,例如:
bigListToIterate.each {
if (it.id > 0 && it.id % 50 == 0) {
cleanGorm()
}
//CRUD action
}
但这不适用于 Grails 4.0.1;虽然没有抛出异常,但更改仍然没有反映在 db 中。
我怎样才能完成它?
我正在使用:
compile "org.grails.plugins:hibernate5"
compile "org.hibernate:hibernate-core:5.4.0.Final"
Mysql版本:
SELECT version();
'5.7.21'
如果我检查数据库,我可以看到表中的行数正在增加并且表的数据长度正在增加,但是当我运行 MySQL 查询 select * from table 时,直到整个函数结束,我才能得到任何结果.
【问题讨论】:
标签: hibernate grails flush hibernate-5.x grails-4