记一次,SQLFeatureNotSupportedException

一、背景

1. springboot由2.3.12.RELEASE升级到3.1.6

2. 配套的mybatis由1.3.0升级到3.0.3

二、现象

1. 项目中提示SQLFeatureNotSupportedException异常,部分异常堆栈如下:

org.springframework.dao.InvalidDataAccessApiUsageException: Error attempting to get column 'onlineTime' from result set.  Cause: java.sql.SQLFeatureNotSupportedException
; null
	at org.springframework.jdbc.support.SQLExceptionSubclassTranslator.doTranslate(SQLExceptionSubclassTranslator.java:106)
	at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:73)
	at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:82)
	at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:92)
	at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:439)
	at jdk.proxy2/jdk.proxy2.$Proxy99.selectList(Unknown Source)
	at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:224)
	at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:147)
	at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:80)
	at org.apache.ibatis.binding.MapperProxy$PlainMethodInvoker.invoke(MapperProxy.java:141)
	at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:86)

2. cause by 部分的日志如下:

Caused by: java.sql.SQLFeatureNotSupportedException: null
	at com.alibaba.druid.pool.DruidPooledResultSet.getObject(DruidPooledResultSet.java:1771)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at org.apache.ibatis.logging.jdbc.ResultSetLogger.invoke(ResultSetLogger.java:68)
	at jdk.proxy3/jdk.proxy3.$Proxy253.getObject(Unknown Source)
	at org.apache.ibatis.type.LocalDateTimeTypeHandler.getNullableResult(LocalDateTimeTypeHandler.java:39)
	at org.apache.ibatis.type.LocalDateTimeTypeHandler.getNullableResult(LocalDateTimeTypeHandler.java:29)
	at org.apache.ibatis.type.BaseTypeHandler.getResult(BaseTypeHandler.java:86)
	at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.applyAutomaticMappings(DefaultResultSetHandler.java:586)
	at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.getRowValue(DefaultResultSetHandler.java:416)
	at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleRowValuesForSimpleResultMap(DefaultResultSetHandler.java:366)
	at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleRowValues(DefaultResultSetHandler.java:337)
	at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleResultSet(DefaultResultSetHandler.java:310)
	at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleResultSets(DefaultResultSetHandler.java:202)
	at org.apache.ibatis.executor.statement.PreparedStatementHandler.query(PreparedStatementHandler.java:66)
	at org.apache.ibatis.executor.statement.RoutingStatementHandler.query(RoutingStatementHandler.java:80)
	at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:65)
	at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:336)
	at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:158)
	at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:110)
	at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:90)
	at jdk.internal.reflect.GeneratedMethodAccessor46.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at org.apache.ibatis.plugin.Invocation.proceed(Invocation.java:49)
	at com.github.pagehelper.SqlUtil._processPage(SqlUtil.java:401)
	at com.github.pagehelper.SqlUtil.processPage(SqlUtil.java:374)
	at com.github.pagehelper.PageHelper.intercept(PageHelper.java:250)
	at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:59)
	at jdk.proxy2/jdk.proxy2.$Proxy248.query(Unknown Source)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:154)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:147)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:142)
	at jdk.internal.reflect.GeneratedMethodAccessor100.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:425)
三、处理思路和方案

1. 在出问题的sql中进行DATE_FORMAT或在sql下增加@Result指定处理类,均能解决问题。推测是升级了mybatis,是高版本mybatis中TypeHandler有问题。

2. 网上找到一个文章,文章如下:

MyBatis版本升级导致OffsetDateTime入参解析异常问题复盘 - throwable - 博客园 (cnblogs.com)2icon-default.png?t=N7T8https://www.cnblogs.com/throwable/p/13418792.html

3. 计划从日志中看看mybatis如何处理mysql中datetime类型字段的,异常日志中找到如下信息:

at org.apache.ibatis.type.LocalDateTimeTypeHandler.getNullableResult(LocalDateTimeTypeHandler.java:39)

4. 找到问题代码实现类,我的数据库连接池用的是druid,druid的实现类中这里抛出了异常

5. 更换druid版本,出问题的项目中druid版本为1.1.10,更换为1.2.8,高版本druid的实现类发生了变化,此时运行项目无异常

6. 继续看日志,cause by 第一行:Caused by: java.sql.SQLFeatureNotSupportedException: null
    at com.alibaba.druid.pool.DruidPooledResultSet.getObject(DruidPooledResultSet.java:1771)。这里也证明了,从Druid的ResultSet中读数据抛了异常。

四、思考

1.mybatis与druid有版本关联

url /TimeAnalysis/getTimeAnalysisList,异常信息:nested exception is org.apache.ibatis.executor.result.ResultMapException: Error attempting to get column 'reset_day_Time' from result set. Cause: java.lang.NullPointerException org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.executor.result.ResultMapException: Error attempting to get column 'reset_day_Time' from result set. Cause: java.lang.NullPointerException @ApiOperation(value = "设备用时分析列表") @GetMapping("/getTimeAnalysisList") public Result getTimeAnalysisList(PageLimit pageLimit, String equipmentNo, String startTime, String endTime, Integer workState){ if(StringUtils.isEmpty(pageLimit.getOrderNo())){ throw new CustomException(CustomExceptionType.TOKEN_PERRMITRE_ERROR,"订单号必传!"); } if(StringUtils.isEmpty(pageLimit.getLineNo())){ throw new CustomException(CustomExceptionType.TOKEN_PERRMITRE_ERROR,"产线号必传!"); } if(StringUtils.isEmpty(equipmentNo)){ throw new CustomException(CustomExceptionType.TOKEN_PERRMITRE_ERROR,"设备编号必传!"); } DzEquipment equipment = equipmentService.getOne(new QueryWrapper<DzEquipment>() .eq("order_no", pageLimit.getOrderNo()) .eq("line_no", pageLimit.getLineNo()) .eq("equipment_no", equipmentNo)); if(ObjectUtils.isEmpty(equipment)){ throw new CustomException(CustomExceptionType.OK_NO_DATA,"设备不存在!"); } QueryWrapper<DzEquipmentTimeAnalysis> queryWrapper=new QueryWrapper<>(); queryWrapper.eq("device_id",equipment.getId()); if(-1!=workState){ queryWrapper.eq("work_state",workState); } if(!StringUtils.isEmpty(startTime)){ queryWrapper.ge("stop_data",startTime); } if(!StringUtils.isEmpty(endTime)){ queryWrapper.le("stop_data",endTime); } PageHelper.startPage(pageLimit.getPage(), pageLimit.getLimit()); List<DzEquipmentTimeAnalysis> list1= dzEquipmentTimeAnalysisDao.selectList(null); List<DzEquipmentTimeAnalysis> list= dzEquipmentTimeAnalysisDao.selectList(queryWrapper); PageInfo<DzEquipmentTimeAnalysis> info = new PageInfo<>(list); return Result.ok(info.getList(), info.getTotal()); } package com.dzics.data.dzdc.model.entity; import com.baomidou.mybatisplus.annotation.*; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.EqualsAndHashCode; import java.io.Serializable; import java.time.LocalDate; import java.time.LocalTime; import java.util.Date; /** * <p> * * </p> * * @author NeverEnd * @since 2021-10-11 */ @Data @EqualsAndHashCode(callSuper = false) @TableName("dz_equipment_time_analysis") @ApiModel(value = "DzEquipmentTimeAnalysis对象", description = "") public class DzEquipmentTimeAnalysis implements Serializable { private static final long serialVersionUID = 1L; @ApiModelProperty(value = "主键") @TableId(value = "id", type = IdType.ASSIGN_ID) private String id; @ApiModelProperty("设备ID") @TableField("device_id") private String deviceId; @ApiModelProperty(value = "订单编号") @TableField("order_no") private String orderNo; @ApiModelProperty(value = "产线序号") @TableField("line_no") private String lineNo; @ApiModelProperty(value = "设备序号") @TableField("equipment_no") private String equipmentNo; @ApiModelProperty(value = "设备类型(1检测设备,2机床,3机器人)") @TableField("equipment_type") private Integer equipmentType; @TableField("work_state") private Integer workState; @TableField("stop_hour") private Integer stopHour; @TableField("stop_day_Time") private LocalTime stopDayTime; @ApiModelProperty(value = "开始运行时间") @TableField("stop_time") private Date stopTime; @TableField("reset_hour") private Integer resetHour; @TableField("reset_day_Time") private LocalTime resetDayTime = LocalTime.of(0, 0); @ApiModelProperty(value = "停止运行时间") @TableField("reset_time") private Date resetTime; @ApiModelProperty(value = "运行时长毫秒") @TableField("duration") private Long duration; @ApiModelProperty("表示是一次完整录的ID") @TableField("group_id") private Long groupId; @ApiModelProperty(value = "运行日期 2021.1.4 日") @TableField("stop_data") private LocalDate stopData; @ApiModelProperty(value = "机构编码") @TableField("org_code") private String orgCode; @ApiModelProperty(value = "删除状态(0正常 1删除 )") @TableField("del_flag") private Boolean delFlag; @ApiModelProperty(value = "创建人") @TableField("create_by") private String createBy; @ApiModelProperty(value = "创建时间") @TableField(value = "create_time", fill = FieldFill.INSERT) private Date createTime; @ApiModelProperty(value = "更新人") @TableField("update_by") private String updateBy; @ApiModelProperty(value = "更新时间") @TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE) private Date updateTime; }
最新发布
07-29
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值