I'm following the Grails Spring Security Core tutorial in their documentation. When I reach 24.1.5.5, the problems start. I'm instructed to modify Bootstrap.groovy to the following, then run the app:
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
}
}
Running the app gives me this error:
2020-03-31 15:46:19.294 ERROR --- [ restartedMain] o.s.boot.SpringApplication : Application run failed
javax.persistence.TransactionRequiredException: no transaction is in progress at org.hibernate.internal.SessionImpl.checkTransactionNeeded(SessionImpl .java:3586)
I've attempted to use @Transactional to solve this, but it had no impact on the error. Reverting Bootstrap.groovy to its default allows the application to run normally. What is missing (or incorrect) from this tutorial that is causing it to fail?