網(wǎng)站首頁(yè) 編程語(yǔ)言 正文
shardingjdbc+mybatisP+Seata 報(bào)錯(cuò) throw new ShouldNeverHappenException,F(xiàn)ailed to fetch schema of t_user
作者:LuckyWangxs 更新時(shí)間: 2022-07-21 編程語(yǔ)言如果是尋求解決問(wèn)題的,可以劃走了,我這篇帖子是詢問(wèn)問(wèn)題的哈哈哈,實(shí)在抱歉,搞了很久沒(méi)搞定,如果你是大牛 幫我看看
項(xiàng)目用的是SpringCloud SpringCloud alibaba + mybatis plus+druid+shardingjdbc+seata
在做分布式事務(wù)事出現(xiàn)的問(wèn)題,每個(gè)服務(wù)對(duì)應(yīng)自己的數(shù)據(jù)庫(kù),也做了分庫(kù)
比如user表,以u(píng)serId分庫(kù),如果不用shardingjdbc分庫(kù),seata可以正常使用,如果加上shardingjdbc分庫(kù),則報(bào)錯(cuò)如下:
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.executor.ExecutorException: Error preparing statement. Cause: io.seata.common.exception.ShouldNeverHappenException: [xid:192.168.201.159:8091:8494064366571848511]get table meta failed, please check whether the table `t_user` exists.
at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:77) ~[mybatis-spring-1.3.2.jar:1.3.2]
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:446) ~[mybatis-spring-1.3.2.jar:1.3.2]
at com.sun.proxy.$Proxy89.insert(Unknown Source) ~[na:na]
at org.mybatis.spring.SqlSessionTemplate.insert(SqlSessionTemplate.java:278) ~[mybatis-spring-1.3.2.jar:1.3.2]
at com.baomidou.mybatisplus.core.override.PageMapperMethod.execute(PageMapperMethod.java:68) ~[mybatis-plus-core-3.0.3.jar:na]
at com.baomidou.mybatisplus.core.override.PageMapperProxy.invoke(PageMapperProxy.java:64) ~[mybatis-plus-core-3.0.3.jar:na]
at com.sun.proxy.$Proxy91.addSelective(Unknown Source) ~[na:na]
at com.single.service.impl.AccountServiceImpl.buildAndSaveUseAndMappings(AccountServiceImpl.java:321) ~[classes/:na]
at com.single.service.impl.AccountServiceImpl.createAccount(AccountServiceImpl.java:107) ~[classes/:na]
at com.single.service.impl.AccountServiceImpl$$FastClassBySpringCGLIB$$1c3e8fe4.invoke(<generated>) ~[classes/:na]
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) ~[spring-core-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:685) ~[spring-aop-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at com.single.service.impl.AccountServiceImpl$$EnhancerBySpringCGLIB$$b47de357.createAccount(<generated>) ~[classes/:na]
at com.single.controller.AccountController.createAccount(AccountController.java:57) ~[classes/:na]
at sun.reflect.GeneratedMethodAccessor177.invoke(Unknown Source) ~[na:na]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_192]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_192]
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:190) [spring-web-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138) [spring-web-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:106) [spring-webmvc-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:888) [spring-webmvc-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:793) [spring-webmvc-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) [spring-webmvc-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1040) [spring-webmvc-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943) [spring-webmvc-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) [spring-webmvc-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909) [spring-webmvc-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:660) [tomcat-embed-core-9.0.29.jar:9.0.29]
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) [spring-webmvc-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741) [tomcat-embed-core-9.0.29.jar:9.0.29]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) [tomcat-embed-core-9.0.29.jar:9.0.29]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-9.0.29.jar:9.0.29]
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) [tomcat-embed-websocket-9.0.29.jar:9.0.29]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [tomcat-embed-core-9.0.29.jar:9.0.29]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-9.0.29.jar:9.0.29]
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100) [spring-web-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) [spring-web-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [tomcat-embed-core-9.0.29.jar:9.0.29]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-9.0.29.jar:9.0.29]
at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93) [spring-web-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) [spring-web-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [tomcat-embed-core-9.0.29.jar:9.0.29]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-9.0.29.jar:9.0.29]
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201) [spring-web-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) [spring-web-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [tomcat-embed-core-9.0.29.jar:9.0.29]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-9.0.29.jar:9.0.29]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202) [tomcat-embed-core-9.0.29.jar:9.0.29]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) [tomcat-embed-core-9.0.29.jar:9.0.29]
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:526) [tomcat-embed-core-9.0.29.jar:9.0.29]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139) [tomcat-embed-core-9.0.29.jar:9.0.29]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) [tomcat-embed-core-9.0.29.jar:9.0.29]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74) [tomcat-embed-core-9.0.29.jar:9.0.29]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) [tomcat-embed-core-9.0.29.jar:9.0.29]
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:367) [tomcat-embed-core-9.0.29.jar:9.0.29]
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) [tomcat-embed-core-9.0.29.jar:9.0.29]
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:860) [tomcat-embed-core-9.0.29.jar:9.0.29]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1591) [tomcat-embed-core-9.0.29.jar:9.0.29]
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-9.0.29.jar:9.0.29]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_192]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_192]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-9.0.29.jar:9.0.29]
at java.lang.Thread.run(Thread.java:748) [na:1.8.0_192]
Caused by: org.apache.ibatis.executor.ExecutorException: Error preparing statement. Cause: io.seata.common.exception.ShouldNeverHappenException: [xid:192.168.201.159:8091:8494064366571848511]get table meta failed, please check whether the table `t_user` exists.
at org.apache.ibatis.executor.statement.BaseStatementHandler.prepare(BaseStatementHandler.java:97) ~[mybatis-3.4.6.jar:3.4.6]
at org.apache.ibatis.executor.statement.RoutingStatementHandler.prepare(RoutingStatementHandler.java:59) ~[mybatis-3.4.6.jar:3.4.6]
at org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:85) ~[mybatis-3.4.6.jar:3.4.6]
at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:49) ~[mybatis-3.4.6.jar:3.4.6]
at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:117) ~[mybatis-3.4.6.jar:3.4.6]
at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:76) ~[mybatis-3.4.6.jar:3.4.6]
at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:198) ~[mybatis-3.4.6.jar:3.4.6]
at org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:185) ~[mybatis-3.4.6.jar:3.4.6]
at sun.reflect.GeneratedMethodAccessor178.invoke(Unknown Source) ~[na:na]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_192]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_192]
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:433) ~[mybatis-spring-1.3.2.jar:1.3.2]
... 61 common frames omitted
Caused by: io.seata.common.exception.ShouldNeverHappenException: [xid:192.168.201.159:8091:8494064366571848511]get table meta failed, please check whether the table `t_user` exists.
at io.seata.rm.datasource.sql.struct.cache.AbstractTableMetaCache.getTableMeta(AbstractTableMetaCache.java:69) ~[seata-all-1.4.2.jar:1.4.2]
at io.seata.rm.datasource.AbstractConnectionProxy.prepareStatement(AbstractConnectionProxy.java:115) ~[seata-all-1.4.2.jar:1.4.2]
at sun.reflect.GeneratedMethodAccessor152.invoke(Unknown Source) ~[na:na]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_192]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_192]
at org.apache.ibatis.logging.jdbc.ConnectionLogger.invoke(ConnectionLogger.java:55) ~[mybatis-3.4.6.jar:3.4.6]
at com.sun.proxy.$Proxy118.prepareStatement(Unknown Source) ~[na:na]
at org.apache.ibatis.executor.statement.PreparedStatementHandler.instantiateStatement(PreparedStatementHandler.java:87) ~[mybatis-3.4.6.jar:3.4.6]
at org.apache.ibatis.executor.statement.BaseStatementHandler.prepare(BaseStatementHandler.java:88) ~[mybatis-3.4.6.jar:3.4.6]
... 72 common frames omitted
在網(wǎng)上查了很久,依舊沒(méi)有找到解決方案,大部分說(shuō)是由于user表沒(méi)有主鍵,或者是用了聯(lián)合主鍵,或者是主鍵沒(méi)有自增,或者是使用的mybatis plus自帶的插入方法,sql中不帶主鍵字段,都嘗試過(guò)了,依舊是這個(gè)問(wèn)題
下面是代碼:
@Override
@Transactional(rollbackFor = ArithmeticException.class)
@ShardingTransactionType(TransactionType.BASE)
public ReturnResponse<LoginRespDTO> smsLogin(LoginReqDTO reqDTO) {
log.info("【 驗(yàn)證碼登錄入?yún)?】{}", JSON.toJSON(reqDTO));
LoginRespDTO resp = new LoginRespDTO();
try {
// 發(fā)送驗(yàn)證碼后會(huì)將驗(yàn)證碼存入redis, 5分鐘有效, 在登錄的時(shí)候要從redis取, 如果取時(shí)異常, rpc短信服務(wù)去mysql查
code = RedisUtil.get(CommonConstants.CAPTCHA_REDIS_PREFIX + reqDTO.getPhone() + 3);
} catch (Exception e) {
ReturnResponse<SmsSendRecordDTO> sendRecord = smsClient.findSendRecord(reqDTO.getPhone());
// .....
}
if (this.checkVerifyCode(code, resp, reqDTO.getSmsCode())) {
log.error("【 smsLogin -> 驗(yàn)證碼校驗(yàn)失敗 】{}", JSON.toJSON(resp));
return ReturnResponse.fail(resp);
}
AccountReqDTO accountReqDTO = new AccountReqDTO();
this.buildAccountReqDTO(accountReqDTO, reqDTO);
ReturnResponse<AccountRespDTO> accountByPhone = accountClient.findAccountByPhone(accountReqDTO);
AccountRespDTO user = accountByPhone.getData();
long userId = -1L;
if (user == null) {
// 首次注冊(cè), 送積分
ReturnResponse<AccountRespDTO> account = accountClient.createAccount(accountReqDTO);
if (!account.isSuccess()) {
log.error("【 smsLogin -> 用戶注冊(cè)失敗 】{}", JSON.toJSON(account));
return ReturnResponse.fail(RtnConstant.REGISTER_FAIL_CODE, RtnConstant.REGISTER_FAIL_MSG);
}
// 注冊(cè)返現(xiàn)邏輯省略...
log.info("【 注冊(cè)成功... 】");
} else {
userId = user.getUserId();
}
// 生成token
String token = this.tokenService.createToken(userId);
resp.setToken(token);
resp.setLoginResult(true);
UserContext.addRtnResultMap(resp);
log.info("【 登錄成功.. 】");
return ReturnResponse.success(resp);
}
也寫了aop把事務(wù)模式設(shè)置為BASE,當(dāng)feign調(diào)用account服務(wù)創(chuàng)建賬戶時(shí),插入分庫(kù)的user表就會(huì)報(bào)最開(kāi)始的異常。表有主鍵沒(méi)有問(wèn)題,不知道有了解的大神幫忙解決下不
原文鏈接:https://blog.csdn.net/qq_41563912/article/details/125392370
相關(guān)推薦
- 2023-07-13 css對(duì)盒模型的理解
- 2023-02-12 redis如何清理緩存_Redis
- 2022-12-24 c++類成員函數(shù)如何做函數(shù)參數(shù)_C 語(yǔ)言
- 2022-05-18 React?Hook之使用Effect?Hook的方法_React
- 2024-03-17 基于linux使用Centos7實(shí)現(xiàn)Samba服務(wù)器安裝和配置(超詳細(xì))
- 2022-12-12 C++?Boost?Chrono實(shí)現(xiàn)計(jì)時(shí)碼表流程詳解_C 語(yǔ)言
- 2022-06-16 使用golang如何優(yōu)雅的關(guān)機(jī)或重啟操作示例_Golang
- 2022-04-09 一起來(lái)了解python的if流程控制_python
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運(yùn)行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲(chǔ)小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運(yùn)算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過(guò)濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯(cuò)誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實(shí)現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡(jiǎn)單動(dòng)態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對(duì)象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊(duì)列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支