0

In a Quarkus 2.5.1 application running in non-native mode I have the following service:

@ApplicationScoped
@Traced
public class BossService {
    @Scheduled(cron = "0 * * ? * *", identity = "boss-job")
    @Transactional
    public void decayMultiplier() {
        // Some code updating entities
    }
}

which works most of the time, but sometimes in production I have the following error:

[api-5f6d6477fd-lbjgj] 2021-12-05 20:04:00,036 INFO  [org.qua.cor.JobRunShell] (QuarkusQuartzScheduler_Worker-6) Job io.quarkus.scheduler.Scheduler.boss-job threw a JobExecutionException: : org.quartz.JobExecutionException: javax.persistence.TransactionRequiredException: no transaction is in progress [See nested exception: javax.persistence.TransactionRequiredException: no transaction is in progress]
[api-5f6d6477fd-lbjgj]  at io.quarkus.quartz.runtime.QuartzScheduler$InvokerJob.execute(QuartzScheduler.java:454)
[api-5f6d6477fd-lbjgj]  at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
[api-5f6d6477fd-lbjgj]  at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573)
[api-5f6d6477fd-lbjgj] Caused by: javax.persistence.TransactionRequiredException: no transaction is in progress
[api-5f6d6477fd-lbjgj]  at org.hibernate.internal.AbstractSharedSessionContract.checkTransactionNeededForUpdateOperation(AbstractSharedSessionContract.java:431)
[api-5f6d6477fd-lbjgj]  at org.hibernate.internal.SessionImpl.checkTransactionNeededForUpdateOperation(SessionImpl.java:3492)
[api-5f6d6477fd-lbjgj]  at org.hibernate.internal.SessionImpl.find(SessionImpl.java:3399)
[api-5f6d6477fd-lbjgj]  at org.hibernate.internal.SessionImpl.find(SessionImpl.java:3381)
[api-5f6d6477fd-lbjgj]  at io.quarkus.hibernate.orm.runtime.session.TransactionScopedSession.find(TransactionScopedSession.java:186)
[api-5f6d6477fd-lbjgj]  at io.quarkus.hibernate.orm.runtime.session.ForwardingSession.find(ForwardingSession.java:78)
[api-5f6d6477fd-lbjgj]  at org.hibernate.Session_5b93bee577ae2f8d76647de04cfab36afbf52958_Synthetic_ClientProxy.find(Unknown Source)
[api-5f6d6477fd-lbjgj]  at io.quarkus.hibernate.orm.panache.common.runtime.AbstractJpaOperations.findById(AbstractJpaOperations.java:181)
[api-5f6d6477fd-lbjgj]  at com.zerator.zunivers.entity.boss.Spawn.findById(Spawn.java)
[api-5f6d6477fd-lbjgj]  at com.zerator.zunivers.entity.boss.Spawn.findCurrentSpawn(Spawn.java:40)
[api-5f6d6477fd-lbjgj]  at com.zerator.zunivers.service.BossService.decayMultiplier(BossService.java:62)
[api-5f6d6477fd-lbjgj]  at com.zerator.zunivers.service.BossService_Subclass.decayMultiplier$$superforward1(Unknown Source)
[api-5f6d6477fd-lbjgj]  at com.zerator.zunivers.service.BossService_Subclass$$function$$1.apply(Unknown Source)
[api-5f6d6477fd-lbjgj]  at io.quarkus.arc.impl.AroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:54)
[api-5f6d6477fd-lbjgj]  at io.opentracing.contrib.interceptors.OpenTracingInterceptor.wrap(OpenTracingInterceptor.java:95)
[api-5f6d6477fd-lbjgj]  at io.opentracing.contrib.interceptors.OpenTracingInterceptor_Bean.intercept(Unknown Source)
[api-5f6d6477fd-lbjgj]  at io.quarkus.arc.impl.InterceptorInvocation.invoke(InterceptorInvocation.java:41)
[api-5f6d6477fd-lbjgj]  at io.quarkus.arc.impl.AroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:50)
[api-5f6d6477fd-lbjgj]  at io.quarkus.narayana.jta.runtime.interceptor.TransactionalInterceptorBase.invokeInCallerTx(TransactionalInterceptorBase.java:302)
[api-5f6d6477fd-lbjgj]  at io.quarkus.narayana.jta.runtime.interceptor.TransactionalInterceptorRequired.doIntercept(TransactionalInterceptorRequired.java:40)
[api-5f6d6477fd-lbjgj]  at io.quarkus.narayana.jta.runtime.interceptor.TransactionalInterceptorBase.intercept(TransactionalInterceptorBase.java:57)
[api-5f6d6477fd-lbjgj]  at io.quarkus.narayana.jta.runtime.interceptor.TransactionalInterceptorRequired.intercept(TransactionalInterceptorRequired.java:32)
[api-5f6d6477fd-lbjgj]  at io.quarkus.narayana.jta.runtime.interceptor.TransactionalInterceptorRequired_Bean.intercept(Unknown Source)
[api-5f6d6477fd-lbjgj]  at io.quarkus.arc.impl.InterceptorInvocation.invoke(InterceptorInvocation.java:41)
[api-5f6d6477fd-lbjgj]  at io.quarkus.arc.impl.AroundInvokeInvocationContext.perform(AroundInvokeInvocationContext.java:41)
[api-5f6d6477fd-lbjgj]  at io.quarkus.arc.impl.InvocationContexts.performAroundInvoke(InvocationContexts.java:32)
[api-5f6d6477fd-lbjgj]  at com.zerator.zunivers.service.BossService_Subclass.decayMultiplier(Unknown Source)
[api-5f6d6477fd-lbjgj]  at com.zerator.zunivers.service.BossService_ClientProxy.decayMultiplier(Unknown Source)
[api-5f6d6477fd-lbjgj]  at com.zerator.zunivers.service.BossService_ScheduledInvoker_decayMultiplier_2556507341812b205cfeaaf7c51477bd85359ecc.invokeBean(Unknown Source)
[api-5f6d6477fd-lbjgj]  at io.quarkus.arc.runtime.BeanInvoker.invoke(BeanInvoker.java:20)
[api-5f6d6477fd-lbjgj]  at io.quarkus.quartz.runtime.QuartzScheduler$InvokerJob.execute(QuartzScheduler.java:452)
[api-5f6d6477fd-lbjgj]  ... 2 more

How can a @Transactional annoted method throw a no transaction is in progress error? Am I missing something?

Benjamin Gamard
  • 308
  • 3
  • 9
  • did you check the options discussed here: https://stackoverflow.com/questions/18399006/spring-transactional-scheduled-method-throws-transactionexception ? – fladdimir Dec 05 '21 at 22:48

1 Answers1

0

Well, while looking at the stack trace it seems that a transaction was already associated with the calling thread when the interceptor for @Transactional was invoked:

at io.quarkus.narayana.jta.runtime.interceptor.TransactionalInterceptorRequired.doIntercept(TransactionalInterceptorRequired.java:40`

We will need more information to find out more. Feel free to create a new issue: https://github.com/quarkusio/quarkus/issues

Martin Kouba
  • 1,121
  • 5
  • 8