Skip to content
This repository has been archived by the owner on Jan 18, 2022. It is now read-only.

TransactionRequiredException in Grails 4 #91

Open
verglor opened this issue Sep 15, 2019 · 3 comments
Open

TransactionRequiredException in Grails 4 #91

verglor opened this issue Sep 15, 2019 · 3 comments

Comments

@verglor
Copy link

verglor commented Sep 15, 2019

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
Copy link
Author

verglor commented Sep 15, 2019

Workaround is to configure hibernate.allow_update_outside_transaction = true

@xpusostomos
Copy link

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
Copy link
Author

verglor commented Mar 18, 2021

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants