I'm working on a Grails (transactional) service which builds a complex domain structure and persists it. The logic works by identifying a previous structure, then creating a new structure and then -- if it passes validation -- removing any old structure and persisting the new one. Grails flush modes are getting in the way, because the validation logic does queries, which in AUTO mode persists parts of the domain structure before it is complete.
I have set in DataSource.groovy:
hibernate {
flush.mode = "commit"
}
because I need (I think) to turn off the AUTO handling which flushes on query. Without this, parts of my new structure are being written incrementally during the validation process, which causes Hib开发者_如何学编程ernate to throw hideous integrity errors.
During my integration test -- despite the setting in DataSource.groovy -- the flush mode is still logged as AUTO. Is there a good reason why Grails shouldn't respect my setting?
The default cascade behaviour is save-update for one-to-many relationship. Try cascade none
static mapping = {
foos cascade:'none'
}
精彩评论