gpt4 book ai didi

hibernate - 刷新页面时 grails 中奇怪的 GORM 行为 (F5)

转载 作者:行者123 更新时间:2023-12-02 23:23:13 24 4
gpt4 key购买 nike

我有一个实体(作者)和一个呈现所有作者的 Controller 操作。

def index = {
def list = Author.list()
render(view: 'index', model: ['allauthors' : list])
}

渲染页面时,将按预期执行单个查询:

Hibernate: 
select
this_.id as id0_0_,
this_.version as version0_0_,
this_.name as name0_0_
from
author this_

但是,当我按“刷新”(F5) 时,将为每个作者执行一个选择语句(这里我有 3 个作者):

Hibernate: 
select
author0_.id as id0_0_,
author0_.version as version0_0_,
author0_.name as name0_0_
from
author author0_
where
author0_.id=?
Hibernate:
select
author0_.id as id0_0_,
author0_.version as version0_0_,
author0_.name as name0_0_
from
author author0_
where
author0_.id=?
Hibernate:
select
author0_.id as id0_0_,
author0_.version as version0_0_,
author0_.name as name0_0_
from
author author0_
where
author0_.id=?

为什么会出现这种情况???

最佳答案

看起来这与查询缓存有关。如果你有

cache.use_query_cache = true

在您的 Datasource.groovy 中,但没有在域类中设置缓存,缓存似乎会逐出每个 list() 上的所有条目,并且必须重新缓存每个条目(只是猜测)。

如果您向域添加缓存,则多个选择就会消失 - 事实上,当我在添加此内容后刷新时,不会执行任何选择:

static mapping = {
cache true
}

关于hibernate - 刷新页面时 grails 中奇怪的 GORM 行为 (F5),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10293527/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com