mysql - grails 和 mysql 批处理

标签 mysql hibernate grails batch-processing

我正在尝试执行在 this great blog post for batch processing in grails with MySQL 中找到的建议.我遇到的问题是在我的循环中包含对 session.clear() 的定期调用会导致抛出 org.hibernate.LazyInitializationException。页面的评论部分引用了以下内容:

You’re second point about potentially causing LIEs is absolutely true. If you’re doing other things outside of importing with the current thread, you’ll want to make sure to reattach any objects to the session after you’re doing your clearing.

但是我该怎么做呢?谁能帮助我具体了解如何“在完成清除后将任何对象重新附加到 session ?”

我还对并行化数据库插入过程感兴趣,这样我就可以利用多核处理器。谁能提供有关如何在 Grails 中执行此操作的建议?

最佳答案

Grails 有一些方法可以帮助解决这个问题(它们在幕后利用 hibernate )。

如果您知道某个对象已分离,您可以使用 attach重新连接它的方法。

如果您在分离对象时对其进行了更改,则可以使用 merge .

如果出于某种原因,您不确定对象是否已附加到 session ,您可以使用 link text判断它是否存在的方法。

可能还值得查看有关 Session 的 Hibernate 文档.

关于mysql - grails 和 mysql 批处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3419173/

相关文章:

php - Magento:无法登录到管理员

grails - Grails maxSize约束不会使texbox变大

java - 在独立应用程序中使用@Transactional

java - JPA (hibernate) 按字段映射子对象

java - 如何解决 jpa 和 hibernate 一对一注释与 doSecondPass 异常

security - 有没有办法让 <g :link calls POST instead of GET?

grails - 迁移Grails 2.4 MultipleCompilationErrorsException

mysql 字符串不像列

mysqldump 分隔文本和结构

mysql - MySQL 中第一个表更新后,如何更新第二个表?