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

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

In short Yes!, if you want to use the object immediately as you are doing in your code.

I faced same problem, so this is the picture I got after reading some refs.

This is hibernate session issue.
Hibernate session is created when controller action is called and ends when the action returns ( or dies with error early). If a code is not calling any transactional code Hibernate’s db interaction can be depicted like this:
Assume the entry action name is actionName and call to the action completes without any error.

NB:The middle bar ( 2nd level cache is disabled) because there is no any transactional code.
without transaction without error

if the above same code has error:

without transaction with error

But if your action is calling transactional method or is creating inline transaction with withTransaction ( and assume the call to the action completed without any error).
with transaction without error

If the above code has an error:
with transaction with error

I hope it helps, but if I made any error or missed to include big point , comment me I will update my pics.

Leave a Comment