Shardingjdbc(1)SQLFeatureNotSupportedExcept: isValid,getObject with type,Can not update sharding key

1.数据库健康检查,isValid()

org.springframework.dao.InvalidDataAccessApiUsageException: ConnectionCallback; isValid; nested exception is java.sql.SQLFeatureNotSupportedException: isValid

解决方案1.:

management:
  health:
    db:
      enabled: false #关闭数据库健康检查isValid

解决方案2:创建一个配置文件DataSourceHealthConfig.java

2.记录一次datetime转LocalDateTime报错,getObject with type

org.springframework.dao.InvalidDataAccessApiUsageException: Error attempting to get column 'create_time' from result set.  Cause: java.sql.SQLFeatureNotSupportedException: getObject with type
; getObject with type; nested exception is java.sql.SQLFeatureNotSupportedException: getObject with type

解决方案:

具体可参考下面地址详细解说!

Cause: java.sql.SQLFeatureNotSupportedException: getObject with type-CSDN博客

配置文件中添加mybatis-typehandlers-jsr310组件包

     <!--mybatis-typehandlers-jsr310必须在mybatis-plus-boot-starter前面-->   
<dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis-typehandlers-jsr310</artifactId>
            <version>1.0.1</version>
        </dependency>


        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
        </dependency>

3.Can not update sharding key

原因分析:

1.在使用sharding-jdbc分表中,本人采用了create_time作为分表字段,

2.Preparing:UPDATE sharding_order SET name=?, create_time=?,  updater=? WHERE id=? 

Parameters: 商品-update(String), 2022-07-10 15:59:53.0(Timestamp), null, 1040294735639478272(Long)

3.可以发现,其中create_time被更新了,而sharding-jdbc只允许更新create_time字段的值必须和原有值一样,才不会报错,数据库存储的时 2022-07-10 15:59:53,最新时2022-07-10 15:59:53.0(变化了)(数据库设计字段位datetime类型,java为LocalDateTime )(不太明白为什么多了一个.0,大佬看到帮忙解释下)

4.解决方案:

        1.新建一个字段存储格式位YMD的

         2.添加注解,updateStrategy = FieldStrategy.NEVER,永久不更新这个字段

@TableField(fill = FieldFill.INSERT, updateStrategy = FieldStrategy.NEVER)
    private LocalDateTime createTime;

  • 11
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值