- I have searched the issues of this repository and believe that this is not a duplicate.
Ⅰ. Issue Description
We have a couple of microservices build with Spring Boot, postgresql and we use thrift for inner communication.
When i run a global transaction through microservices, i get: no transaction is in progress; nested exception is javax.persistence.TransactionRequiredException
Ⅱ. Describe what happened
The error happens when we use jpa's saveAndFlush(), but when we use save(), it works fine no error, but it doesn't save at all.
The globaltransaction is created fine in SEATA client (no local transactions though in the case of save() method).
If there is an exception, please attach the exception trace:
When we use save() this is the logs it generates, also it says commited but it is not commited.
With save():
2022-10-05 12:05:57.266 INFO [,,,] 13732 --- [nio-9093-exec-9] i.seata.tm.api.DefaultGlobalTransaction : Begin new global transaction [192.168.1.101:8091:5530733769509556240]
2022-10-05 12:05:58.591 INFO [,,,] 13732 --- [nio-9093-exec-9] c.b.t.v.service.TVehiclePortService : # createVehicleGroup... xid: TX_XID
2022-10-05 12:05:58.593 INFO [,,,] 13732 --- [nio-9093-exec-9] c.b.t.v.service.TVehiclePortService : # createVehicleGroup... xid: TX_XID
2022-10-05 12:06:10.693 INFO [,,,] 13732 --- [ctor_RMROLE_1_1] i.s.c.r.n.AbstractNettyRemotingClient : channel [id: 0x35a8bb0d, L:/127.0.0.1:54499 - R:/127.0.0.1:8091] read idle.
2022-10-05 12:06:10.701 INFO [,,,] 13732 --- [ctor_RMROLE_1_1] i.s.core.rpc.netty.NettyPoolableFactory : will destroy channel:[id: 0x35a8bb0d, L:/127.0.0.1:54499 - R:/127.0.0.1:8091]
2022-10-05 12:06:10.702 INFO [,,,] 13732 --- [ctor_RMROLE_1_1] i.s.c.r.n.AbstractNettyRemotingClient : ChannelHandlerContext(AbstractNettyRemotingClient$ClientHandler#0, [id: 0x35a8bb0d, L:/127.0.0.1:54499 - R:/127.0.0.1:8091]) will closed
2022-10-05 12:06:10.703 INFO [,,,] 13732 --- [ctor_RMROLE_1_1] i.s.c.r.n.AbstractNettyRemotingClient : ChannelHandlerContext(AbstractNettyRemotingClient$ClientHandler#0, [id: 0x35a8bb0d, L:/127.0.0.1:54499 ! R:/127.0.0.1:8091]) will closed
2022-10-05 12:06:10.704 INFO [,,,] 13732 --- [ctor_RMROLE_1_1] i.s.c.r.netty.NettyClientChannelManager : return to pool, rm channel:[id: 0x35a8bb0d, L:/127.0.0.1:54499 ! R:/127.0.0.1:8091]
2022-10-05 12:06:10.704 INFO [,,,] 13732 --- [ctor_RMROLE_1_1] i.s.core.rpc.netty.NettyPoolableFactory : channel valid false,channel:[id: 0x35a8bb0d, L:/127.0.0.1:54499 ! R:/127.0.0.1:8091]
2022-10-05 12:06:10.704 INFO [,,,] 13732 --- [ctor_RMROLE_1_1] i.s.core.rpc.netty.NettyPoolableFactory : will destroy channel:[id: 0x35a8bb0d, L:/127.0.0.1:54499 ! R:/127.0.0.1:8091]
2022-10-05 12:06:10.704 INFO [,,,] 13732 --- [ctor_RMROLE_1_1] i.s.c.r.n.AbstractNettyRemotingClient : ChannelHandlerContext(AbstractNettyRemotingClient$ClientHandler#0, [id: 0x35a8bb0d, L:/127.0.0.1:54499 ! R:/127.0.0.1:8091]) will closed
2022-10-05 12:06:10.705 INFO [,,,] 13732 --- [ctor_RMROLE_1_1] i.s.c.r.n.AbstractNettyRemotingClient : ChannelHandlerContext(AbstractNettyRemotingClient$ClientHandler#0, [id: 0x35a8bb0d, L:/127.0.0.1:54499 ! R:/127.0.0.1:8091]) will closed
2022-10-05 12:06:10.705 INFO [,,,] 13732 --- [ctor_RMROLE_1_1] i.s.c.r.n.AbstractNettyRemotingClient : channel inactive: [id: 0x35a8bb0d, L:/127.0.0.1:54499 ! R:/127.0.0.1:8091]
2022-10-05 12:06:10.706 INFO [,,,] 13732 --- [ctor_RMROLE_1_1] i.s.core.rpc.netty.NettyPoolableFactory : channel valid false,channel:[id: 0x35a8bb0d, L:/127.0.0.1:54499 ! R:/127.0.0.1:8091]
2022-10-05 12:06:10.706 INFO [,,,] 13732 --- [ctor_RMROLE_1_1] i.s.core.rpc.netty.NettyPoolableFactory : will destroy channel:[id: 0x35a8bb0d, L:/127.0.0.1:54499 ! R:/127.0.0.1:8091]
2022-10-05 12:06:10.706 INFO [,,,] 13732 --- [ctor_RMROLE_1_1] i.s.c.r.n.AbstractNettyRemotingClient : ChannelHandlerContext(AbstractNettyRemotingClient$ClientHandler#0, [id: 0x35a8bb0d, L:/127.0.0.1:54499 ! R:/127.0.0.1:8091]) will closed
2022-10-05 12:06:10.707 INFO [,,,] 13732 --- [ctor_RMROLE_1_1] i.s.c.r.n.AbstractNettyRemotingClient : ChannelHandlerContext(AbstractNettyRemotingClient$ClientHandler#0, [id: 0x35a8bb0d, L:/127.0.0.1:54499 ! R:/127.0.0.1:8091]) will closed
2022-10-05 12:06:10.713 INFO [,,,] 13732 --- [nio-9093-exec-9] i.seata.tm.api.DefaultGlobalTransaction : Suspending current transaction, xid = 192.168.1.101:8091:5530733769509556240
2022-10-05 12:06:10.715 INFO [,,,] 13732 --- [nio-9093-exec-9] i.seata.tm.api.DefaultGlobalTransaction : [192.168.1.101:8091:5530733769509556240] commit status: Committed
With saveAndFlush():
common.exception.BaseRuntimeException: General server error
at com.common.handler.DomainExceptionHandler.doOnError(DomainExceptionHandler.java:49)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:634)
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:617)
at org.springframework.aop.aspectj.AspectJAfterThrowingAdvice.invoke(AspectJAfterThrowingAdvice.java:68)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:750)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:123)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:388)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:119)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:750)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:97)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:750)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:692)
at com.bravo.domain.service.DriverDomainService$$EnhancerBySpringCGLIB$$f70ec819.create(<generated>)
at com.bravo.thrift.driver.service.TDriverPortService.create(TDriverPortService.java:55)
at com.bravo.thrift.driver.controller.TDriverController.create(TDriverController.java:23)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
at org.springframework.aop.framework.adapter.ThrowsAdviceInterceptor.invoke(ThrowsAdviceInterceptor.java:113)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.aop.framework.adapter.AfterReturningAdviceInterceptor.invoke(AfterReturningAdviceInterceptor.java:57)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:58)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at ru.trylogic.spring.boot.thrift.aop.MetricsThriftMethodInterceptor.invoke(MetricsThriftMethodInterceptor.java:22)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:215)
at com.sun.proxy.$Proxy148.create(Unknown Source)
at com.bravo.thrift.driver.TDriverService$Processor$create.getResult(TDriverService.java:651)
at com.bravo.thrift.driver.TDriverService$Processor$create.getResult(TDriverService.java:630)
at org.apache.thrift.ProcessFunction.process(ProcessFunction.java:38)
at org.apache.thrift.TBaseProcessor.process(TBaseProcessor.java:38)
at org.apache.thrift.server.TServlet.doPost(TServlet.java:83)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:652)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:733)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at com.common.filter.SeataFilter.doFilter(SeataFilter.java:44)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.doFilterInternal(WebMvcMetricsFilter.java:93)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:542)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:143)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:374)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:888)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1597)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: org.springframework.dao.InvalidDataAccessApiUsageException: no transaction is in progress; nested exception is javax.persistence.TransactionRequiredException: no transaction is in progress
at org.springframework.orm.jpa.EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(EntityManagerFactoryUtils.java:403)
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:235)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.translateExceptionIfPossible(AbstractEntityManagerFactoryBean.java:551)
at org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:61)
at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:242)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:152)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:174)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:97)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:215)
at com.sun.proxy.$Proxy146.saveAndFlush(Unknown Source)
at com.bravo.domain.service.DriverDomainService.create(DriverDomainService.java:63)
at com.bravo.domain.service.DriverDomainService$$FastClassBySpringCGLIB$$47a868b7.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:779)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:750)
at org.springframework.aop.aspectj.AspectJAfterThrowingAdvice.invoke(AspectJAfterThrowingAdvice.java:64)
... 78 common frames omitted
Caused by: javax.persistence.TransactionRequiredException: no transaction is in progress
at org.hibernate.internal.AbstractSharedSessionContract.checkTransactionNeededForUpdateOperation(AbstractSharedSessionContract.java:413)
at org.hibernate.internal.SessionImpl.checkTransactionNeededForUpdateOperation(SessionImpl.java:3397)
at org.hibernate.internal.SessionImpl.doFlush(SessionImpl.java:1354)
at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1349)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.java:362)
at com.sun.proxy.$Proxy142.flush(Unknown Source)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:311)
at com.sun.proxy.$Proxy142.flush(Unknown Source)
at org.springframework.data.jpa.repository.support.SimpleJpaRepository.flush(SimpleJpaRepository.java:604)
at org.springframework.data.jpa.repository.support.SimpleJpaRepository.saveAndFlush(SimpleJpaRepository.java:573)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.springframework.data.repository.core.support.RepositoryMethodInvoker$RepositoryFragmentMethodInvoker.lambda$new$0(RepositoryMethodInvoker.java:289)
at org.springframework.data.repository.core.support.RepositoryMethodInvoker.doInvoke(RepositoryMethodInvoker.java:137)
at org.springframework.data.repository.core.support.RepositoryMethodInvoker.invoke(RepositoryMethodInvoker.java:121)
at org.springframework.data.repository.core.support.RepositoryComposition$RepositoryFragments.invoke(RepositoryComposition.java:524)
at org.springframework.data.repository.core.support.RepositoryComposition.invoke(RepositoryComposition.java:285)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$ImplementationMethodExecutionInterceptor.invoke(RepositoryFactorySupport.java:531)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.doInvoke(QueryExecutorMethodInterceptor.java:156)
at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.invoke(QueryExecutorMethodInterceptor.java:131)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:80)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:123)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:388)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:119)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:137)
... 92 common frames omitted
Ⅲ. Describe what you expected to happen
I really need a fix for this, as we still are considering going with Seata or with something else, but besides this, everything is looking great with Seata, so a help will be appreciated.
Ⅳ. How to reproduce it (as minimally and precisely as possible)
- xxx
- xxx
- xxx
Ⅴ. Anything else we need to know?
Ⅵ. Environment:
- JDK version : 11
- Seata version: 1.5.2
- OS : MACOS
- Others:
2条答案
按热度按时间arknldoa1#
The current information doesn't seem to have anything to do with seata, so can you provide a demo
k0pti3hp2#
Yes, i used this sample: https://github.com/vir56k/java_demo/tree/master/seata_demo
Then implemented similar to what we have.
So first, we have a gateway which communicates with other microservices through thrift(RPC).
The issue is that, when i used RestTemplate to communicate with another microservice, it worked fine.
But when i communicate with Thrift, i get the above issues, mainly no transaction in progress.
One question i have, whether it is Rest or RPC or any communication, the only info Thrift needs it is the header tx right?
Because if yes, you can see in gateway module i have Service1ThriftClient, where i have a bean of THttpClient, which i use on the service to send tx_id in the header. And the transactionId is received successfully, as i am able to catch that in the filter, and the RootContext.bind(txId) is successfully executed.
Thanks for your help.
seata_demo2.zip