class Author {
static hasMany = [books: Book]
String name
}
class Book {
static hasMany = [chapters: Chapter]
String title
}
class Chapter {
String chapter
}
如果我想查找所有作者
Author.findAll()
,是否也有办法忽略被拉入内存的章节关系?
最佳答案
f I am trying to find all authors Author.findAll() , is there a way to ignore the chapter relationships that are being pulled into memory as well?
是。这就是默认情况下会发生的情况。在完全按照您所显示的方式编写域类的情况下,
Author.findAll()
将生成这样的SQL(确切的语法可能会有所不同,具体取决于您所使用的方言,这将是针对H2生成的):select author0_.id as id1_0_, author0_.version as version2_0_, author0_.name as name3_0_ from author author0_
如果您开始与
Author
实例进行交互并引用books
属性,则将触发更多的sql发送到数据库。希望对您有所帮助。
关于hibernate - 使用动态查找器时,是否可以忽略hasMany关系?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59987541/