-
Notifications
You must be signed in to change notification settings - Fork 8.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bugfix: fix when seata and jpa are used together, their AutoConfiguration order is incorrect #5092
Conversation
…ate correct transaction manager for different orm framework.
...-client/src/main/java/io/seata/spring/boot/autoconfigure/SeataTCCFenceAutoConfiguration.java
Outdated
Show resolved
Hide resolved
Codecov Report
@@ Coverage Diff @@
## develop #5092 +/- ##
=============================================
- Coverage 49.25% 49.23% -0.02%
+ Complexity 4131 4130 -1
=============================================
Files 737 737
Lines 26188 26188
Branches 3234 3234
=============================================
- Hits 12898 12894 -4
- Misses 11913 11915 +2
- Partials 1377 1379 +2
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM please register pr to develop.md https://github.com/seata/seata/tree/develop/changes
问下,在修改前,会报什么样的错误?麻烦提供下异常日志信息吧。 |
@wangliang181230 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@wangliang181230 |
@zhuyoufeng 这样不行,只有TM没有数据源的服务,会启动失败。
强制将 我在你的测试代码里亲测有效。 |
另外,建议去jpa的开源项目里提个issue。推荐他们添加该文件。 |
这个不正确吧,没有datasource,transactionmanager也不会创建成功啊。我依然认为你不应该判断是否存在bean,或可以判断conditiononclass,因为强制这样控制顺序,破坏的是加载顺序 并且,个人认为开发者是在引入seata之后出现的transactionmanager不正确的情况,不应该由开发人员去处理其加载顺序。 |
对于seata自身来说,tcc的auto类的定义是没有问题的,它的确是依赖于bean,而不是class。因为有class但用户并没有创建bean时,这个tcc的auto也不应生效,所以不推荐改成OnClass。 正如你说的,jpa的加载顺序因为引入了seata,而破坏了jpa与jdbc的加载顺序。但也不应该因为引入了jpa而破坏了seata与jdbc(或 目前最明确的问题的确是jpa没有显式定义其加载顺序before于jdbc,而导致的问题,并不是因为引入了seata而破坏了其加载顺序,因为seata自身的定义并没有问题,这有点把责任推给了seata的感觉。 |
DataSourceTransactionManagerAutoConfiguration 中已经使用了 AutoConfigureOrder 控制顺序了,只是这个顺序被seata的starter破坏了,你可以试一下你们 1.4.2 的版本有没有这个问题。 如果你认为没必要,可以 reject。 |
经过测试,使用你的解决方案,tcc的auto,在你的项目中的确没有生效了。验证了前面的疑问。 |
因为1.4.2还没有tcc的auto类。
并不是没必要,seata1.5.2和jpa的确存在冲突,是需要寻找最佳解决方案的。目前正在跟你讨论呢。 |
在你的测试代码里,经过几种尝试,还是添加 你是否有其他的解决方案? |
我们先罗列一下需要解决的问题吧,这样比较清晰一些。
|
...-client/src/main/java/io/seata/spring/boot/autoconfigure/SeataTCCFenceAutoConfiguration.java
Show resolved
Hide resolved
我的想法还是移除 @ConditionalOnBean(type = {"javax.sql.DataSource", "org.springframework.transaction.PlatformTransactionManager"}) 这个代码,其他的暂时没有。 理由:
|
@zhuyoufeng 你认为的原来的加载顺序,就是jpa在jdbc之前啊。 |
部分公司的数据源都是在下层dao服务层的,上层是提供API的,API层只使用seata的TM,并不使用RM。 |
@slievrly @a364176773 然后再看下,我提供的建议:
|
@zhuyoufeng 想到个好办法。
这样的话就不需要等jpa那修改,也能够兼容了。 |
我试试 |
@wangliang181230 @AutoConfigureAfter({SeataCoreAutoConfiguration.class, TransactionAutoConfiguration.class}) |
昨天在 所以,这个BUG的解决方案是在 麻烦再改一版本吧。 |
@wangliang181230 Done. |
@zhuyoufeng 不好意思,刚看了一下你上次提交的那个,也是可以的。 麻烦两个都加着吧。
这样更保险。 |
AutoConfiguration
order is incorrect
AutoConfiguration
order is incorrectseata
and jpa
are used together, their AutoConfiguration
order is incorrect
seata
and jpa
are used together, their AutoConfiguration
order is incorrectThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@wangliang181230 好了,你看下。 |
嗯,可以了,稍后我merge下。 |
1.6.0 快发布了,到时候你可以升级上去。 |
好的,谢谢 |
1.6.0-RC1 候选版本先发布了,你可以先试用看看。 |
👌 |
…o 1114_for_5073 * '1114_for_5073' of https://github.com/zw201913/seata: bugfix: hikari datasource auto proxy fail (apache#5134) bugfix: rollback active xa connection fail (apache#5131) optimize: support oracle on delete tccfence logs (apache#5124) feature: support passing `contextPath` parameter to Nacos client (apache#5111) bugfix:NPE caused when there is no @GlobalTransactional annotation on the RM side (apache#5109) bugfix: Druid disable oracle implicit cache (apache#5098) bugfix: fix access key loss after server restart (apache#5097) optimize: remove druid dependency in ConnectionProxy (apache#5104) bugfix:fix ClassNotFoundException during the ZK unit test (apache#5101) bugfix: fix when seata and jpa are used together, their AutoConfiguration order is incorrect (apache#5092) optimize: lock priority attempts to insert (apache#4681) bugfix: update join condition placeholder param error (apache#5052)
Ⅰ. Describe what this PR did
This PR is used to ensure springboot create correct transaction manager for different ORM framework.
The original code shows that this configuration SeataTCCFenceAutoConfiguration must be executed after DataSourceTransactionManagerAutoConfiguration, but for springboot, different transaction manager for different ORM framework. this DataSourceTransactionManagerAutoConfiguration will create DataSourceTransactionManager which works for jdbc related ORM, not work for JPA.
Ⅱ. Does this pull request fix one issue?
Ⅲ. Why don't you add test cases (unit test/integration test)?
Ⅳ. Describe how to verify it
Removed this config. It will be work because this config SeataTCCFenceAutoConfiguration already set the "ConditionalOnBean" with "org.springframework.transaction.PlatformTransactionManager". And the order is correct now.
Ⅴ. Special notes for reviews