0

我有一个实体产品和实体内部,我有 Contry 实体。

当我执行 Product.find 或 Product.get 并获取国家/地区值时,我的国家/地区值只有 id 值,但在国家实体中,我有 id、名称和代码 [id: 1, code:null, name:null],但这情况是间歇性的,99% 的时间值被加载 [id:1, code: XXX, name:YYYYY]。

我认为这是一个缓存问题,但我不在开发人员环境中模拟,只是在生产环境中

我的国家域名:

class Country implements Serializable {

private static final long serialVersionUID = 1

def i18NService

String name
String code

static mapping = {
    cache true
}

Country(String code, String name) {
    this()
    this.name = name
    this.code = code
}

这是一个 grails/hibernate 缓存错误?我如何模拟这种情况?

4

1 回答 1

0

您没有显示您的产品域,因此很难确定,但这听起来像是一个急切/懒惰的获取问题。基本上,引用的域对象可能会或可能不会与您的另一个域对象一起获取。

您可以在此处查看文档:http ://docs.grails.org/latest/ref/Database%20Mapping/lazy.html急切和延迟获取都对性能产生了非常重要的影响,所以不要盲目地改变它。基本上,如果您在使用 Product 时总是需要 Country,您可能应该将其设为急切获取。如果没有,您应该根据需要刷新 Country。

于 2018-10-11T16:12:50.943 回答