beanww commented on issue #7686: URL: https://github.com/apache/incubator-seata/issues/7686#issuecomment-3392820792
> 单独设置[@transactional](https://github.com/transactional)(readOnly = true)后,你DS就切换不了数据源了,加上DSTransactional可以切换数据源,但是目前它没有支持readOnly配置,要不你把[@transactional](https://github.com/transactional)(readOnly = true)、@DSTransactional和@GlobalTransactional都加上看看是什么结果【/捂脸】,这样还不行的话,就只能拆成远程服务调用的方式了 ----------------- 经过验证: 1. 如下,是无法切换数据源的: @GlobalTransactional @Transactional(rollbackFor = Exception.class) @DSTransactional 2. 如下,是可以切换数据源的,而且还解决了我上面说的select也开事务分支的问题,即:既可以切换数据源,又不会产生大量的分支事务,但是seata-xa下,这两个事务注解混合使用是否会有问题呢?而且还是之前说的,我们的@Transactional注解可能无法去掉,因为要确保不开启seata时本地事务可用,所以这个方案似乎还是不敢用 @GlobalTransactional @DSTransactional 3. 如下,会报错 @GlobalTransactional @Transactional(rollbackFor = Exception.class, readOnly = true) @DSTransactional 这样报错: ### SQL: SELECT NEXTVAL('share_seq') ### Cause: org.postgresql.util.PSQLException: 错误: 不能在一个只读模式的事务中执行nextval() ; uncategorized SQLException; SQL state [25006]; error code [0]; 错误: 不能在一个只读模式的事务中执行nextval() at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:93) at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:439) at jdk.proxy2/jdk.proxy2.$Proxy188.selectOne(Unknown Source) at org.mybatis.spring.SqlSessionTemplate.selectOne(SqlSessionTemplate.java:160) at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.execute(MybatisMapperMethod.java:87) at com.baomidou.mybatisplus.core.override.MybatisMapperProxy$PlainMethodInvoker.invoke(MybatisMapperProxy.java:152) at com.baomidou.mybatisplus.core.override.MybatisMapperProxy.invoke(MybatisMapperProxy.java:89) at jdk.proxy2/jdk.proxy2.$Proxy200.selectQQENextUserIdSeq(Unknown Source) at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103) at java.base/java.lang.reflect.Method.invoke(Method.java:580) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:355) at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:196) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) at com.baomidou.dynamic.datasource.aop.DynamicDataSourceAnnotationInterceptor.invoke(DynamicDataSourceAnnotationInterceptor.java:57) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:223) at jdk.proxy2/jdk.proxy2.$Proxy201.selectQQENextUserIdSeq(Unknown Source) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
