English 中文(简体)
Hibernate/GORM: collection was not processed by flush()
原标题:

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.

I found a possible solution here.

Actually, look at toString, equals, hashcode and make sure you are not accessing your lazy accessor.

I know I am talking about java and here the question is about grails but maybe there is the same kind of thing for grails.

Don t hesitate to edit.

It was the issue for me (in java)

The only time I ve encountered that exeception is when using Hibernate events e.g. beforeInsert, beforeUpdate etc - are you using these?

There s an issue in JIRA related to this which has been fixed for Grails 1.2

I had that error when a tried to add element to a collection after delete elements from the collection. I solved it by calling save(flush:true) before add new elements to the collection.

  • In my case, the collection is always returned from a select.




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签