package com.mycompany.myapp

class BootStrap {

   def init = {

         def adminRole = new Role(authority: 'ROLE_ADMIN').save()

         def testUser = new User(username: 'me', password: 'password').save()

         UserRole.create testUser, adminRole

         UserRole.withSession {
            it.flush()
            it.clear()
         }

         assert User.count() == 1
         assert Role.count() == 1
         assert UserRole.count() == 1

   }
}

package com.mycompany.myapp

import grails.gorm.transactions.Transactional

class BootStrap {
    def init = {
        addTestUser()
    }

    @Transactional
    void addTestUser() {
        def adminRole = new Role(authority: 'ROLE_ADMIN').save()

        def testUser = new User(username: 'me', password: 'password').save()

        UserRole.create testUser, adminRole

        UserRole.withSession {
            it.flush()
            it.clear()
        }

        assert User.count() == 1
        assert Role.count() == 1
        assert UserRole.count() == 1
    }
}

Fix bootstrap for required tx in hibernate 5.2+
Fix bootstrap for required tx in hibernate 5.2+
