kefirfromperm / grails-asynchronous-mail

The Grails Asynchronous Mail plugin
http://grails.org/plugin/asynchronous-mail
21 stars 36 forks source link

TransactionRequiredException in Grails 4 #91

Open verglor opened 5 years ago

verglor commented 5 years ago

It seems there are missing transaction declarations - see GORM manual section 1.2.5:

Job GRAILS_JOBS.grails.plugin.asyncmail.AsynchronousMailJob threw a JobExecutionException:

org.quartz.JobExecutionException: no transaction is in progress
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
        at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:80)
        at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrapNoCoerce.callConstructor(ConstructorSite.java:105)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:257)
        at grails.plugins.quartz.QuartzDisplayJob.execute(QuartzDisplayJob.groovy:43)
        at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
        at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573)
Caused by: javax.persistence.TransactionRequiredException: no transaction is in progress
        at org.hibernate.internal.SessionImpl.checkTransactionNeeded(SessionImpl.java:3586)
        at org.hibernate.internal.SessionImpl.doFlush(SessionImpl.java:1447)
        at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1443)
        at javax.persistence.EntityManager$flush$0.call(Unknown Source)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callSafe(AbstractCallSite.java:82)
        at grails.plugins.quartz.QuartzDisplayJob.flushSession(QuartzDisplayJob.groovy:60)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.codehaus.groovy.runtime.callsite.PlainObjectMetaMethodSite.doInvoke(PlainObjectMetaMethodSite.java:43)
        at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:190)
        at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:58)
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:51)
        at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:63)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:168)
        at grails.plugins.quartz.QuartzDisplayJob.execute(QuartzDisplayJob.groovy:35)
        ... 2 common frames omitted
verglor commented 5 years ago

Workaround is to configure hibernate.allow_update_outside_transaction = true

xpusostomos commented 3 years ago

I think this is the wrong solution. After grails 3.1 services aren't transactional by default. The AsynchronousMailProcessService isn't marked as @Transactional. The correct solution is to mark the service as transactional. Doing global hibernate workarounds is bad because plugins shouldn't assume a particular global setup.

verglor commented 3 years ago

@xpusostomos you are right, it's just a quick workaround. That's why this issue is still open and unresolved.