Grails 3 Hibernate Interceptor

Recently we underwent some performance pain points with transactions in grails 3. After some investigation it became apparent that the default transactional behavior in grails services post 3.1 wasn’t actually disabled by default as per the docs here.

The first step was to submit the issue to grails-core and to work with the core grails team to devise a solution. Ultimately, I submitted this accepted pull request. That will fix our excessive transaction count and execution time in grails 3.1.4+ by default.

To see that we were creating and using a lot of transactions we created the following interceptor named HibernateInterceptor.groovy. To use the interceptor you need to have logging set to info and set the following in your application.yml

hibernate.filter.enabled: true

This interceptor showed us that we were using something like Transaction Count: 23. That was not acceptable for an action that should have had 3 or 4 at the most. It was creating transactions at all the service boundaries.

For grails 3.1.0 through 3.1.3 you can disable this behavior by default by setting the following property in your application.yml

grails.spring.transactionManagement.proxies: false