Hibernate 在Grails中同时包含惰性和非惰性属性的缓存
Grails文档指出Hibernate 在Grails中同时包含惰性和非惰性属性的缓存,hibernate,grails,orm,associations,ehcache,Hibernate,Grails,Orm,Associations,Ehcache,Grails文档指出 class Person { .. static mapping = { table 'people' cache true } } “将配置包含惰性和非惰性属性的‘读写’缓存。” 如果我们有一对多的个人关系,例如: static hasMany = [addressess: Address] grails是否将其视为惰性属性? 地址对象是否也被缓存,或者只有与给定人员相关的ID被保存在缓存中?默认情况下,关联在G
class Person {
..
static mapping = {
table 'people'
cache true
}
}
“将配置包含惰性和非惰性属性的‘读写’缓存。”
如果我们有一对多的个人关系,例如:
static hasMany = [addressess: Address]
grails是否将其视为惰性属性?
地址对象是否也被缓存,或者只有与给定人员相关的ID被保存在缓存中?默认情况下,关联在Grails中被视为是惰性的 在上面的
个人
的特定示例中,所有
地址对象都将被缓存。上述默认缓存设置可以扩展为:
cache usage: 'read-write', include: 'all' //includes lazy and non-lazy
为了只缓存人员
中的关联,您需要
cache usage: 'read-write', include: 'non-lazy'
//usage can be according to the need 'read-only', 'read-write', etc
地址缓存:true
为了从Person
缓存中放弃关联,您需要
cache usage: 'read-write', include: 'non-lazy'
//usage can be according to the need 'read-only', 'read-write', etc
我已经安装了grails melody插件,在那里我可以检查ehcache中的内容。通过像grails文档中那样完成映射,我可以在melody raport中看到Person缓存,但没有地址缓存。如果你写的是真的,为什么我看不到地址缓存?