-1
的Grails 1.3.7与MySQL 5.5removeFrom与级联全删除,孤儿不工作
要么我必须做一些脑死亡,或者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!")
}
}
但是,当我浏览到本地主机:在保存过程中(:8080 /富/作家/指数我得到一个“foo.Book.author非空属性引用null或瞬时值” )
我并不真正了解GORM内部结构或Hibernate(代理与非代理实例),我尝试了使用'get'而不是'find'的所有组合,但无法使其工作。有人可以解释这是如何工作的吗?
嗯我试着切换报价,但它没有帮助。也尝试切换到hsqldb,这也没有做任何事情...... – 2011-04-19 20:47:29
@约翰:其实,这不是报价。请注意“静态映射=”和“静态约束= ...” – 2011-04-20 00:48:41
Doh!你当然是对的。绝对是在脑死亡的范畴。我想知道我是否可以从Stackoverflow关闭/删除这个问题 - 不会向社区添加任何内容。 – 2011-04-20 08:18:42