5

エンティティ(作成者)と、すべての作成者をレンダリングするコントローラーアクションがあります。

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)を押すと、作成者ごとにselectステートメントが実行されます(ここでは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=?

なぜこれが起こったのですか?

4

1 に答える 1

1

これはクエリキャッシュに関係しているようです。あなたが持っている場合

cache.use_query_cache = true

Datasource.groovy にあるが、ドメイン クラスにキャッシュが設定されていない場合、キャッシュはそれぞれのすべてのエントリを削除し、それぞれlist()を再キャッシュする必要があるようです (推測にすぎません)。

ドメインにキャッシュを追加すると、複数の選択がなくなります-実際、これを追加した後に更新すると、選択は行われません:

static mapping = {
    cache true
}
于 2012-07-14T23:51:40.713 に答える