带有级联的全删除孤儿的removeFrom不起作用

|| 使用MySQL 5.5的Grails 1.3.7 我必须做一些脑子死了的事情,或者这与Grails问题有关http://jira.grails.org/browse/GRAILS-5804和http://jira.grails.org/browse/GRAILS-4121等。 我有:
class Author {
    String name
    static hasMany = [books: Book]
    static constraints = {
        books cascade: \'all-delete-orphan\'
    }
    String toString() {
        return name
    }
}

class Book {
    String title
    static belongsTo = [author: Author]
    static constraints = {
    }
    String toString() {
        return title
    }
}

Bootstrap:
def a = new Author(name: \'Author0\')
a.save(flush: true, failOnError: true)      
def b = new Book(title: \'Book0\')
a.addToBooks(b).save(flush: true, failOnError: true)

class AuthorController {
    def index = {
        println(\"Controller code: \" + \"Old books by author: \" + Author.get(1).books)
        def author = Author.findByName(\"Author0\")
        def oldBooks = []
        oldBooks += author.books  // to avoid ConcurrentModificationException
        oldBooks.each {
            author.removeFromBooks(it)
        }
        author.save(flush: true, failOnError: true)
        println(\"Controller code: \" + \"New books by author: \" + Author.get(1).books)
            render(\"All done!\")
        }
    }
但是当我导航到localhost:8080 / foo / author / index时,在save()期间得到一个\'not-null属性引用一个空值或瞬态值:foo.Book.author \' 我不太了解GORM内部或Hibernate(代理与未代理实例),我尝试使用\'get \'而不是\'find \'的所有组合,但无法使其正常工作。有人可以解释这应该如何工作吗?     
已邀请:
我认为您放错了约束,应该是这样的:
static mapping = {
    books cascade: \"all-delete-orphan\"
}
static constraints = {
    books cascade: \'all-delete-orphan\'
}
这导致了问题。有关此GORM陷阱的更多信息,请参见此处(删除子项)。     

要回复问题请先登录注册