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

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

问题描述

当我尝试保存类型为 Member

的实体时,我的Grails应用程序中有一个集成测试,失败了

  invitingMember.save(flush:true)

以下例外


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


在事务之前,我将一个对象添加到 invitingMember 的集合属性中。我的猜测是,上面的行引发了异常,因为只是在这一点上,添加到集合中的对象才会持久。

潜在的问题可能是Hibernate没有级联保存。所以当你刷新 Member 时,Hibernate发现集合仍然很脏(这可能不是你想要的)。因此,要么手动刷新收藏夹,要么告诉Hibernate级联所有更新


I have an integration test in my Grails application that fails when I try to save an entity of type Member

invitingMember.save(flush: true)

This raises the following exception

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

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.

解决方案

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.

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

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