grails / grails-quartz

This project provides integration of the Quartz scheduling framework into the Grails Framework
http://grails.org/plugin/quartz
Apache License 2.0
76 stars 90 forks source link

Job calling a service ignores @Transactinal annotations #82

Open erichelgeson opened 7 years ago

erichelgeson commented 7 years ago

Job:

class ExampleJob {
  def someService
  void execute() {
    someService.method()
  }
}

Service:

@Transactional
class SomeService {
  @Transactional(readOnly=true)
  def method() {
    // do lots work
  }
}

I would expect method called from the job would be a readOnly transaction. I only noticed it wasn't while I had sql logging on and noticed a bunch of dirty checks/updates.

It seems to ignore the annotation, adding Propagation.REQUIRES_NEW was not honored either.

If this same someService.method() is called from a controller it was readOnly as expected.

Only way to work around it was to not use the annotation but do Domain.withNewTransaction(readOnly: true) { .work. }