Open davidbairdala opened 5 years ago
Anyone aware of a work around?
+1
We have the same problem with Grails 4.0.0.
In our case the problem only exists, when we use chained afterInsert methods.
Domainclass A has afterInsert that creates eight domainclasses of B and saves them (all in a service). Domainclass B has afterInsert that creates one domainclasses of C and saves it (all in a service).
In the afterInsert of A and B we use Domainclass.withNewSession{}.
The Exception is thrown after all service methods are done in the line where in domainclass A the withNewSession code starts.
This issue still exists in grails 5.1.1
Domain.withNewSession {
Domain.get(1) // load some domain object into the new session.
service.anyTransactionMethod() // can do nothing.
}
the service method runs, but an exception is thrown when the newSession ends.
Task List
Steps to Reproduce
Expected Behaviour
The links marked as 'Will fail' should succeed without an exception
Actual Behaviour
Links marked as 'Will fail' will throw an exception with the message 'An active connection is required'
It seems that if code inside a withNewSession block calls a method on another service that is marked as Transactional then the exception will occur. It doesn't make any difference if the second service method actually makes use of the database or not.
Stack trace
Environment Information
Example Application
https://github.com/davidbairdala/active-connection-required-grails-bug.git