withTransaction for Quartz Jobs in Grails?
-
21-12-2019 - |
Question
When I set a Grails Quartz job like this:
class TestJob {
static triggers = {
simple repeatInterval: 5000l // execute job once in 5 seconds
}
def execute() {
def users = User.getAll()
users.each { user ->
user.enabled = true
user.save()
}
}
}
Do I have to wrap the content of execute in a withTransaction block?
Solution
Only if you need the transaction.
Actually, the Quartz plugin creates a persistence context, but doesn't create a transaction.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow