|
I'm having the exact same issue as described in this bug. A temp workaround for the bug: count() the children before you save() ... in the case of the example provided (untested!): WooController.groovy class WooController {
def index = {
Parent p = Parent.get(1)
p.addToChilds(new Child(s:"testy"))
// kludge! avoids GRAILS-4453
//
p.childs*.subChilds?.count()
Parent.withTransaction
{
p.save(flush:true)
}
render "${p} -> ${p.childs}"
}
}
This is a Hibernate bug, basically you can't access a collection that hasn't been initialized from an event. see http://opensource.atlassian.com/projects/hibernate/browse/HHH-2763 but how is it possible, that everything works fine with 1.1? The error only occurs with 1.1.1 here, and the hibernate bugreport is from 2007. Something must have changed between 1.1 and 1.1.1, the hibernate codebase should be the same in both versions I originally got this is 1.1 (which is what I'm still working with), and I simply avoided this issue with a workaround. However when I tried upgrading to 1.1.1 something else seemed to break in my app with the same error (can't remember the specifics), so it seems the error may be more prevalent in 1.1.1 than 1.1, but is definitely in both. Probably because we upgraded to the latest version of Hibernate in Grails 1.1.1 and it may deal with things differently. Unfortunately we can't account for Hibernate bugs. The only solution I can think of right now is to execute each event with its own session and document the fact the you have to re-read your objects state in a separate session So I patched Hibernate to fix the issue and make the error go away. However, updates to child elements inside an event don't work too well, you need to flush the session a second time in order for these to propogate. Having said that this may not be noticable in a controller since if you flush the session once explicitly it will then get flushed again when the action completes or when the service transcation commits Yeah see my note in i just tried to upgrade to grails 1.2M3 Why? 2009-11-03 15:12:37,109 [http-8080-4] ERROR hibernate.AssertionFailure - an assertion failure occured (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session) Create an issue and attach an example that reproduces the problem |
|||||||||||||||||||||||||||||||||||||||||
I've created a "similiar" issue about delete() methods not being called from beforeDelete events. I don't have a clue if these are related but thought they have some similarities since they both involve beforeXXXX.
http://jira.codehaus.org/browse/GRAILS-4434