【问题标题】:"no transaction is in progress" in @Transactional service method@Transactional 服务方法中的“没有正在进行的事务”
【发布时间】:2021-12-05 19:35:00
【问题描述】:

在以非本地模式运行的 Quarkus 2.5.1 应用程序中,我有以下服务:

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

大部分时间都有效,但有时在生产中我会遇到以下错误:

[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

@Transactional 注释方法如何引发no transaction is in progress 错误?我错过了什么吗?

【问题讨论】:

标签: quarkus


【解决方案1】:

好吧,在查看堆栈跟踪时,似乎在调用 @Transactional 的拦截器时,事务已经与调用线程相关联:

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

我们需要更多信息才能了解更多信息。随意创建一个新问题:https://github.com/quarkusio/quarkus/issues

【讨论】:

猜你喜欢
  • 2017-03-04
  • 1970-01-01
  • 2017-07-24
  • 1970-01-01
  • 1970-01-01
  • 2016-01-31
  • 2013-02-22
  • 2014-04-25
  • 2012-07-29
相关资源
最近更新 更多