According to the official documentation and the books I read, the services are transnational by default. however, we were getting records even if we immediately throw a RuntimeException.
eg:
class MyService { def someMethod() { new someDomainObject().save(failOnError:true) throw new RuntimeException("rollback!") } }
and calling it like this:
class myController{ MyService myService def someMethod() { myService.someMethod() } }
In the above case, after calling the controller that calls the service, then, checking whether the row was created by attaching to the database using mysql tools, the row was actually executed and not rolled back.
So, we tried the following:
class MyService { static transactional = true def someMethod() { new someDomainObject().save(failOnError:true) throw new RuntimeException("rollback!") } }
Same problem.
Next we tried this:
@Transactional class MyService { static transactional = true def someMethod() { new SomeDomainObject().save(failOnError:true) throw new RuntimeException("rollback!") } }
Finally it works. However, we do not understand why.
Note: Grails 2.4.4 using MYSQL:
development { dataSource { dbCreate = "create-drop" url = "jdbc:mysql://127.0.0.1:3306/db" username = "user" password = "***" } }
Is this normal behavior?
Is @Transactional different from static tranasctional = true?
Service classes were generated using intellij 14 using the "new groovy class" option from the Services folder in the Grails view. The option “new Grails service” does not work for us, it just doesn’t do anything, so we have to create all the groovy classes “manually” in the right place.