休眠/GORM:flush() 未处理集合 [英] Hibernate/GORM: collection was not processed by flush()

查看:20
本文介绍了休眠/GORM:flush() 未处理集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试保存 Member

invitingMember.save(flush: true)

这引发了以下异常

org.hibernate.AssertionFailure:收藏[com.mycompany.facet.Facet.channels] 是未由 flush() 处理com.mycompany.member.MemberConnectionService.addOrUpdateContact(MemberConnectionService.groovy:939)

org.hibernate.AssertionFailure: collection [com.mycompany.facet.Facet.channels] was not processed by flush() at com.mycompany.member.MemberConnectionService.addOrUpdateContact(MemberConnectionService.groovy:939)

在事务的早期,我将一个对象添加到 invitingMember 的集合属性中.我的猜测是在上面那行抛出异常,因为只有在这一点上,添加到集合中的对象才被持久化.

Earlier in the transaction I add an object to a collection property of invitingMember. My guess is that the exception is thrown at the line above, because it's only at this point that the object added to the collection is persisted.

推荐答案

潜在的问题可能是 Hibernate 没有级联保存.因此,当您刷新 Member 时,Hibernate 会注意到该集合仍然是脏的(这可能不是您想要的).所以要么手动刷新集合,要么 告诉 Hibernate 级联所有更新.

The underlying problem is probably that Hibernate doesn't cascade the save. So when you flush the Member, Hibernate notices that the collection is still dirty (which is probably not what you want). So either flush the collection manually or tell Hibernate to cascade all the updates.

这篇关于休眠/GORM:flush() 未处理集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆