Author{
String name;
List<Book> books
static hasMany= [books: Book]
}
Book{
int number_of_pages;
String name;
}
我想查询和获取按
number_of_pages
排序的特定作者的前十本书
最佳答案
使用HQL,您可以执行以下操作:
def query = "select book from Author author join author.books book where author=:author order by book.number_of_pages"
def books = Author.executeQuery(query, [author: author], [max: 10])
注意:您应该将
number_of_pages
重命名为numberOfPages
。
关于hibernate - 单向一对多关系查询GORM grails,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13619969/