hibernate - Grails 中包含惰性和非惰性属性的缓存

标签 hibernate grails orm associations ehcache

Grails 文档指出,

class Person {
    ..
    static mapping = {
        table 'people'
        cache true
    }
}

“将配置一个‘读写’缓存,其中包括惰性和非惰性属性。”

如果我们在 Person 中有一对多关系,例如:

static hasMany = [addressess: Address]

grails 是否将其视为惰性属性? Address 对象是否也被缓存,或者只有与给定 Person 相关的 id 被保留在缓存中?

最佳答案

默认情况下,关联在 Grails 中被视为惰性

在上述 Person 的特定示例中,所有 地址对象都将被缓存。上面的默认缓存设置可以扩展为如下所示:

cache usage: 'read-write', include: 'all' //includes lazy and non-lazy

为了仅缓存 Person 内的关联,您需要

地址缓存:true

为了放弃 Person 中缓存的关联,您需要

cache usage: 'read-write', include: 'non-lazy' 
//usage can be according to the need 'read-only', 'read-write', etc

关于hibernate - Grails 中包含惰性和非惰性属性的缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18471419/

相关文章:

spring - JPA @Column 不适用于带有特殊字符的列名

mongodb - Grails投影忽略MongoDB的排序顺序

grails - Groovy-等待 promise list

java - @SecondaryTable 注释不适用于不同架构中的相同表名

java - 通过 Jersey/Grizzly 运行测试时,应该如何以及由谁注入(inject) PersistenceContext?

java - hibernate = 找不到列

java - 使用 Hibernate/Spring/JUnit 设置和拆除复杂的数据库状态

mysql - 在grails应用程序中执行MySQL脚本

hibernate - 如何检查 isDirty ('transient_fieldName' ) 在 Grails 中的 transient 字段

mysql - Sails.js 使用sails-mysql 的日期的水线查询修饰符?