Strange GORM behavior in grails on page refresh (F5)

I have an entity (Author) and a controller action that displays all authors.

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

When rendering the page, one request is executed, as expected:

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

However, when I press Refresh (F5), the select statement is executed for each author (here I have 3 authors):

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=?

Why is this happening???

+5
source share
1 answer

This seems to be related to the request cache. if you have

cache.use_query_cache = true

in your Datasource.groovy, but you don’t have caching configured in your domain class, the cache seems to return all the entries on each list()and should re-cache each of them (just a hunch).

, - , , :

static mapping = {
    cache true
}
+1

All Articles