Unable to translate SQLException with Error code ‘0‘, will now try the fallback translator

博客内容讨论了在Java中遇到的无法翻译SQLException错误,该错误与设置事务为只读有关。在Service层添加了@Transactional(readOnly=true)导致更新操作失败,因为未将只读属性设为false。解决方案在于正确管理和切换事务的只读状态。

Unable to translate SQLException with Error code '0', will now try the fallback translator

发生了这个报错,原因是 jdbc read only,因为在 Service 上增加了:

@Transactional(readOnly = true)

而在更新方法没有增加让只读为 false

图片

: Connection released: [id: 0][route: {}->http://192.168.12.59:6041][total kept alive: 1; route allocated: 1 of 20; total allocated: 1 of 200] 2025-08-29 09:54:39.783 DEBUG 21556 --- [ main] org.mybatis.spring.SqlSessionUtils : Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@68212585] 2025-08-29 09:54:39.925 DEBUG 21556 --- [ main] o.s.b.f.xml.XmlBeanDefinitionReader : Loaded 11 bean definitions from class path resource [org/springframework/jdbc/support/sql-error-codes.xml] 2025-08-29 09:54:39.933 DEBUG 21556 --- [ main] o.s.b.f.s.DefaultListableBeanFactory : Creating shared instance of singleton bean 'DB2' 2025-08-29 09:54:39.965 DEBUG 21556 --- [ main] o.s.b.f.s.DefaultListableBeanFactory : Creating shared instance of singleton bean 'Derby' 2025-08-29 09:54:39.968 DEBUG 21556 --- [ main] o.s.b.f.s.DefaultListableBeanFactory : Creating shared instance of singleton bean 'H2' 2025-08-29 09:54:39.970 DEBUG 21556 --- [ main] o.s.b.f.s.DefaultListableBeanFactory : Creating shared instance of singleton bean 'HDB' 2025-08-29 09:54:39.977 DEBUG 21556 --- [ main] o.s.b.f.s.DefaultListableBeanFactory : Creating shared instance of singleton bean 'HSQL' 2025-08-29 09:54:39.979 DEBUG 21556 --- [ main] o.s.b.f.s.DefaultListableBeanFactory : Creating shared instance of singleton bean 'Informix' 2025-08-29 09:54:39.980 DEBUG 21556 --- [ main] o.s.b.f.s.DefaultListableBeanFactory : Creating shared instance of singleton bean 'MS-SQL' 2025-08-29 09:54:39.983 DEBUG 21556 --- [ main] o.s.b.f.s.DefaultListableBeanFactory : Creating shared instance of singleton bean 'MySQL' 2025-08-29 09:54:39.985 DEBUG 21556 --- [ main] o.s.b.f.s.DefaultListableBeanFactory : Creating shared instance of singleton bean 'Oracle' 2025-08-29 09:54:39.988 DEBUG 21556 --- [ main] o.s.b.f.s.DefaultListableBeanFactory : Creating shared instance of singleton bean 'PostgreSQL' 2025-08-29 09:54:39.991 DEBUG 21556 --- [ main] o.s.b.f.s.DefaultListableBeanFactory : Creating shared instance of singleton bean 'Sybase' 2025-08-29 09:54:39.994 DEBUG 21556 --- [ main] o.s.jdbc.support.SQLErrorCodesFactory : Looking up default SQLErrorCodes for DataSource [com.depower.datasource.config.DynamicDataSource@3596a9d5] 2025-08-29 09:54:39.994 DEBUG 21556 --- [ main] o.s.jdbc.datasource.DataSourceUtils : Fetching JDBC Connection from DataSource 2025-08-29 09:54:39.997 DEBUG 21556 --- [ main] o.s.jdbc.support.SQLErrorCodesFactory : SQL error codes for 'TDengine' not found 2025-08-29 09:54:39.998 DEBUG 21556 --- [ main] o.s.jdbc.support.SQLErrorCodesFactory : Caching SQL error codes for DataSource [com.depower.datasource.config.DynamicDataSource@3596a9d5]: database product name is 'TDengine' 2025-08-29 09:54:40.007 DEBUG 21556 --- [ main] s.j.s.SQLErrorCodeSQLExceptionTranslator : Unable to translate SQLException with Error code '537', will now try the fallback translator 2025-08-29 09:54:40.020 DEBUG 21556 --- [ main] c.d.datasource.aspect.DataSourceAspect : clean datasource
08-30
2025-09-18 15:29:33.615 [reactor-http-nio-5] DEBUG reactor.netty.http.server.HttpServerOperations - [a0e83397, L:/192.168.10.122:9000 - R:/192.168.10.221:51066] New http connection, requesting read 2025-09-18 15:29:33.615 [reactor-http-nio-5] DEBUG reactor.netty.transport.TransportConfig - [a0e83397, L:/192.168.10.122:9000 - R:/192.168.10.221:51066] Initialized pipeline DefaultChannelPipeline{(reactor.left.httpCodec = io.netty.handler.codec.http.HttpServerCodec), (reactor.left.httpTrafficHandler = reactor.netty.http.server.HttpTrafficHandler), (reactor.right.reactiveBridge = reactor.netty.channel.ChannelOperationsHandler)} 2025-09-18 15:29:33.616 [reactor-http-nio-5] DEBUG reactor.netty.http.server.HttpServerOperations - [a0e83397, L:/192.168.10.122:9000 - R:/192.168.10.221:51066] Increasing pending responses, now 1 2025-09-18 15:29:33.616 [reactor-http-nio-5] DEBUG reactor.netty.http.server.HttpServer - [a0e83397-1, L:/192.168.10.122:9000 - R:/192.168.10.221:51066] Handler is being applied: org.springframework.http.server.reactive.ReactorHttpHandlerAdapter@250c00e8 2025-09-18 15:29:33.617 [reactor-http-nio-5] DEBUG o.s.web.server.adapter.HttpWebHandlerAdapter - [a0e83397-4] HTTP PUT "/master/shipper/update" 2025-09-18 15:29:33.617 [reactor-http-nio-5] DEBUG o.s.w.r.r.m.a.RequestMappingHandlerMapping - [a0e83397-4] Mapped to com.hvlink.controller.ShipperController#updateShipper(ShipperDTO) 2025-09-18 15:29:33.617 [reactor-http-nio-5] DEBUG o.s.w.r.r.m.a.RequestBodyMethodArgumentResolver - [a0e83397-4] Content-Type:application/json 2025-09-18 15:29:33.617 [reactor-http-nio-5] DEBUG o.s.w.r.r.m.a.RequestBodyMethodArgumentResolver - [a0e83397-4] 0..1 [com.hvlink.entity.dto.master.ShipperDTO] 2025-09-18 15:29:33.618 [reactor-http-nio-5] DEBUG reactor.netty.channel.FluxReceive - [a0e83397-1, L:/192.168.10.122:9000 - R:/192.168.10.221:51066] [terminated=false, cancelled=false, pending=0, error=null]: subscribing inbound receiver 2025-09-18 15:29:33.618 [reactor-http-nio-5] DEBUG o.s.http.codec.json.Jackson2JsonDecoder - [a0e83397-4] Decoded [ShipperDTO(id=29, companyCode=null, supplierCode=null, supplierName=0012000048 - 上海信耀电子有限公司, shipper (truncated)...] 2025-09-18 15:29:33.618 [reactor-http-nio-5] DEBUG o.s.jdbc.datasource.DataSourceTransactionManager - Creating new transaction with name [com.hvlink.service.impl.ShipperServiceImpl.updateShipper]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT 2025-09-18 15:29:33.618 [reactor-http-nio-5] DEBUG o.s.jdbc.datasource.DataSourceTransactionManager - Acquired Connection [ConnectionID:1 ClientConnectionId: 832daba7-ee0b-4bc1-9a5c-db187f8edc8d] for JDBC transaction 2025-09-18 15:29:33.618 [reactor-http-nio-5] DEBUG o.s.jdbc.datasource.DataSourceTransactionManager - Switching JDBC Connection [ConnectionID:1 ClientConnectionId: 832daba7-ee0b-4bc1-9a5c-db187f8edc8d] to manual commit 2025-09-18 15:29:33.628 [reactor-http-nio-5] DEBUG org.mybatis.spring.SqlSessionUtils - Creating a new SqlSession 2025-09-18 15:29:33.628 [reactor-http-nio-5] DEBUG org.mybatis.spring.SqlSessionUtils - Registering transaction synchronization for SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@6f745882] 2025-09-18 15:29:33.629 [reactor-http-nio-5] DEBUG o.m.spring.transaction.SpringManagedTransaction - JDBC Connection [ConnectionID:1 ClientConnectionId: 832daba7-ee0b-4bc1-9a5c-db187f8edc8d] will be managed by Spring 2025-09-18 15:29:33.629 [reactor-http-nio-5] DEBUG c.h.mapper.master.ShipperMapper.existsOtherDefault - ==> Preparing: SELECT CASE WHEN EXISTS ( SELECT 1 FROM tm_shipper WHERE is_default = '是' ) THEN 1 ELSE 0 END 2025-09-18 15:29:33.629 [reactor-http-nio-5] DEBUG c.h.mapper.master.ShipperMapper.existsOtherDefault - ==> Parameters: 2025-09-18 15:29:33.644 [reactor-http-nio-5] DEBUG c.h.mapper.master.ShipperMapper.existsOtherDefault - <== Total: 1 2025-09-18 15:29:33.644 [reactor-http-nio-5] DEBUG org.mybatis.spring.SqlSessionUtils - Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@6f745882] 2025-09-18 15:29:33.644 [reactor-http-nio-5] DEBUG org.mybatis.spring.SqlSessionUtils - Fetched SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@6f745882] from current transaction 2025-09-18 15:29:33.644 [reactor-http-nio-5] DEBUG c.hvlink.mapper.master.ShipperMapper.updateShipper - ==> Preparing: UPDATE tm_shipper SET company_code = ?, supplier_code = ?, shipper_name = ?, address = ?, contact_person = ?, contact_tel = ?, contact_mobile = ?, is_default = ? WHERE id = ? 2025-09-18 15:29:33.645 [reactor-http-nio-5] DEBUG c.hvlink.mapper.master.ShipperMapper.updateShipper - ==> Parameters: null, null, 发货方AC(String), null, 1(String), null, null, 否(String), 29(Integer) 2025-09-18 15:29:33.660 [reactor-http-nio-5] DEBUG org.mybatis.spring.SqlSessionUtils - Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@6f745882] 2025-09-18 15:29:33.660 [reactor-http-nio-5] DEBUG o.s.j.support.SQLErrorCodeSQLExceptionTranslator - Unable to translate SQLException with Error code '515', will now try the fallback translator 2025-09-18 15:29:33.660 [reactor-http-nio-5] DEBUG o.s.jdbc.support.SQLStateSQLExceptionTranslator - Extracted SQL state class '23' from value '23000' 2025-09-18 15:29:33.661 [reactor-http-nio-5] DEBUG org.mybatis.spring.SqlSessionUtils - Transaction synchronization deregistering SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@6f745882] 2025-09-18 15:29:33.661 [reactor-http-nio-5] DEBUG org.mybatis.spring.SqlSessionUtils - Transaction synchronization closing SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@6f745882] 2025-09-18 15:29:33.661 [reactor-http-nio-5] DEBUG o.s.jdbc.datasource.DataSourceTransactionManager - Initiating transaction rollback 2025-09-18 15:29:33.661 [reactor-http-nio-5] DEBUG o.s.jdbc.datasource.DataSourceTransactionManager - Rolling back JDBC transaction on Connection [ConnectionID:1 ClientConnectionId: 832daba7-ee0b-4bc1-9a5c-db187f8edc8d] 2025-09-18 15:29:33.679 [reactor-http-nio-5] DEBUG o.s.jdbc.datasource.DataSourceTransactionManager - Releasing JDBC Connection [ConnectionID:1 ClientConnectionId: 832daba7-ee0b-4bc1-9a5c-db187f8edc8d] after transaction 2025-09-18 15:29:33.680 [reactor-http-nio-5] DEBUG o.s.w.r.r.m.annotation.ResponseBodyResultHandler - [a0e83397-4] Using 'application/json' given [application/json, text/plain, */*] and supported [application/json, application/*+json, application/x-ndjson, text/event-stream] 2025-09-18 15:29:33.680 [reactor-http-nio-5] DEBUG o.s.w.r.r.m.annotation.ResponseBodyResultHandler - [a0e83397-4] 0..1 [com.hvlink.common.Result<java.lang.String>] 2025-09-18 15:29:33.680 [reactor-http-nio-5] DEBUG o.s.http.codec.json.Jackson2JsonEncoder - [a0e83397-4] Encoding [Result(status=500, msg=<EOL><EOL>### Error updating database. Cause: com.microsoft.sqlserver.jdbc.SQLServer (truncated)...] 2025-09-18 15:29:33.681 [reactor-http-nio-5] DEBUG reactor.netty.http.server.HttpServerOperations - [a0e83397-1, L:/192.168.10.122:9000 - R:/192.168.10.221:51066] Detected non persistent http connection, preparing to close 2025-09-18 15:29:33.681 [reactor-http-nio-5] DEBUG reactor.netty.http.server.HttpServerOperations - [a0e83397-1, L:/192.168.10.122:9000 - R:/192.168.10.221:51066] Last HTTP packet was sent, terminating the channel 2025-09-18 15:29:33.681 [reactor-http-nio-5] DEBUG reactor.netty.channel.ChannelOperations - [a0e83397-1, L:/192.168.10.122:9000 - R:/192.168.10.221:51066] [HttpServer] Channel inbound receiver cancelled (operation cancelled). 2025-09-18 15:29:33.681 [reactor-http-nio-5] DEBUG o.s.web.server.adapter.HttpWebHandlerAdapter - [a0e83397-4] Completed 200 OK
最新发布
09-19
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

码农UP2U

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值