Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 965
Dónal Avatar asked Nov 09 '09 15:11

Dónal


3 Answers

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.

like image 64
Aaron Digulla Avatar answered Nov 19 '22 10:11

Aaron Digulla


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)

like image 29
unludo Avatar answered Nov 19 '22 10:11

unludo


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

like image 2
leebutts Avatar answered Nov 19 '22 10:11

leebutts