GRAILS belongsTo hasMany 查询问题

xiaoxiao2024-04-22  33

[b]这个bug已经在1.1的正式版本中修复。[/b] 举个例子: [i]class Author { static hasMany = [books:Book] } class Book { static belongsTo = [author: Author] }[/i] [b]查询Author:[/b] [i]def criteria = Author.createCriteria() def list = criteria { //conditions } list.each { author-> author.books.each{ } } [/i] 在author.books.each这一步就会导致book的更新(version会变化,有时候会导致乐观锁错误) 改成如下方式可避免: [i]def books = Book.findAllByAuthor(author) books.each { }[/i]
转载请注明原文地址: https://www.6miu.com/read-5015150.html

最新回复(0)