mybaties踩坑之错误的@ID 注解引用, 导致org.apache.ibatis.type.TypeException

在定义完实体类以后, 使用mybaties的主键查询实体类,一查就报错,说无法将字符串格式转换为时间类型,仔细检查了一遍,类型并没有问题,于是尝试将Timestamp的字段去掉再看,仍然报无法将字符串格式转换为Integer类型,基本可以确定问题出在了实体类上。

错误信息如下

2022-04-13 16:11:49.039 [http-nio-8080-exec-1] ERROR c.t.s.m.exceptionadvice.EcrExceptionHandler - [EcrExceptionHandler.java:192] - 出现异常的类为:org.mybatis.spring.MyBatisExceptionTranslator 方法为:translateExceptionIfPossible 第77行 异常信息:{}
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='createTime', mode=IN, javaType=class java.sql.Timestamp, jdbcType=null, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}. Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #8 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: java.lang.ClassCastException: java.lang.String cannot be cast to java.sql.Timestamp
	at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:77)
	at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:446)
	at com.sun.proxy.$Proxy135.selectOne(Unknown Source)
	at org.mybatis.spring.SqlSessionTemplate.selectOne(SqlSessionTemplate.java:166)

实体类
`package com.tianwen.springcloud.microservice.base.entity.content;

import com.tianwen.springcloud.commonapi.base.BaseEntity;
import com.tianwen.springcloud.commonapi.cache.CacheObject;
import com.tianwen.springcloud.commonapi.cache.DataType;
import com.tianwen.springcloud.microservice.base.util.BaseRedisKeyUtil;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.data.annotation.Id;
import javax.persistence.*;
import lombok.EqualsAndHashCode;
import java.sql.Timestamp;

/**

  • 资源表
  • @author xiaozan
  • @version [版本号, 2022年3月28日]
  • @see [相关类/方法]
  • @since [产品/模块版本]
    */

@Data
@Table(name = “t_e_content”)
@EqualsAndHashCode(callSuper = true)
@CacheObject(timeout = 86400000, prefix = BaseRedisKeyUtil.COMMONKEY, name = “t_e_content”, keys = {“contentId”}, type = DataType.STRING)
public class Content extends BaseEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY, generator = "SELECT  nextval('seq_contentid_t_e_content')")
@ApiModelProperty(value = "资源ID")
@Column(name = "contentid")
private String contentId;

@ApiModelProperty(value = "资源名称")
@Column(name = "contentname")
private String contentName;

}`

最终经过对比发现:
我在主键上使用的@ID注解,是单独引入的,来自于 org.springframework.data.annotation.Id;
在这里插入图片描述
javax.persistence.*; 这个里面就包含有@ID 的注解实现,而且@Table,@Column也都是来自于这个包。
在这里插入图片描述
解决办法:
去掉这一行就可以了。
import org.springframework.data.annotation.Id;

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值