hibernate - 使用动态查找器时,是否可以忽略hasMany关系?

标签 hibernate grails gorm dynamic-finders

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/

相关文章:

java - 创建后在 hibernate 中更改模型对象的数据类型

grails - 子查询联接两个级别的父表的命名查询

Grails 不匹配带有可选参数的 url 模式

grails - grails gorm空字段

grails - Grails/Gorm:排序具有许多关系

java - 获取 org.hibernate.InvalidMappingException : unable to read xml when I try to run my program

java - 为什么 Hibernate 重新实现数据库已有的功能?

java - 不支持从 varbinary 到 BLOB 的转换

grails - Groovy日期解析错误

validation - Grails 默认可为空约束