Do I ever need to explicitly flush GORM save calls in grails?

前端 未结 4 1970
说谎
说谎 2020-12-04 12:25

I have a strange situation which appears to indicate a GORM cacheing problem

//begin with all book.status\'s as UNREAD
Book.list().each { book.status = Statu         


        
4条回答
  •  悲&欢浪女
    2020-12-04 13:17

    I wonder what was your FlushMode setting.

    By default it is set to "auto" and it means that session is flushed before every query which hits DB directly (and probably in other cases too). In that case your Foo.findAllByBar should flush the session first (possible performance issue!) and read correct value from the DB.

    There are two other values for FlushMode and if you set one of them then it would explain your problems. First is "manual" which means you decide to manual flush session (e.g. with save(flush:true)). If you don't do that then Foo.findAllByBar reads outdated DB state. Second one is "commit" which means that session is flushed with every transaction commit. That is quite handy if you use "withTransaction" statement in grails.

    Resources: http://schneide.wordpress.com/2011/03/08/the-grails-performance-switch-flush-modecommit/ http://docs.jboss.org/hibernate/entitymanager/3.5/reference/en/html/objectstate.html#d0e1215

提交回复
热议问题