Cause java.sql.SQLDataException Unsupported conversion from LONG to java.sql.Timestamp
今天遇到了一个奇怪的错误,报错如下图所示:
org.springframework.dao.DataIntegrityViolationException: Error attempting to get column 'question_id' from result set. Cause: java.sql.SQLDataException: Unsupported conversion from LONG to java.sql.Timestamp
; Unsupported conversion from LONG to java.sql.Timestamp; nested exception is java.sql.SQLDataException: Unsupported conversion from LONG to java.sql.Timestampat org.springframework.jdbc.support.SQLExceptionSubclassTranslator.doTranslate(SQLExceptionSubclassTranslator.java:84)at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:88)at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:440)at com.sun.proxy.$Proxy140.selectList(Unknown Source)at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:223)at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.executeForMany(MybatisMapperMethod.java:177)at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.execute(MybatisMapperMethod.java:78)at com.baomidou.mybatisplus.core.override.MybatisMapperProxy.invoke(MybatisMapperProxy.java:96)at com.sun.proxy.$Proxy153.selectList(Unknown Source)at cn.tedu.straw.portal.test.mapper.TestTeacherQuestionMapper.selectOne(TestTeacherQuestionMapper.java:32)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)at java.lang.reflect.Method.invoke(Method.java:498)at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)at org.springframework.test.context.junit4.statements.RunBeforeTestExecutionCallbacks.evaluate(RunBeforeTestExecutionCallbacks.java:74)at org.springframework.test.context.junit4.statements.RunAfterTestExecutionCallbacks.evaluate(RunAfterTestExecutionCallbacks.java:84)at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:251)at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97)at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)at org.junit.runners.ParentRunner.run(ParentRunner.java:363)at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190)at org.junit.runner.JUnitCore.run(JUnitCore.java:137)at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: java.sql.SQLDataException: Unsupported conversion from LONG to java.sql.Timestampat com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:114)at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:89)at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:63)at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:73)at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:96)at com.mysql.cj.jdbc.result.ResultSetImpl.getTimestamp(ResultSetImpl.java:903)at com.mysql.cj.jdbc.result.ResultSetImpl.getTimestamp(ResultSetImpl.java:948)at com.zaxxer.hikari.pool.HikariProxyResultSet.getTimestamp(HikariProxyResultSet.java)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)at java.lang.reflect.Method.invoke(Method.java:498)at org.apache.ibatis.logging.jdbc.ResultSetLogger.invoke(ResultSetLogger.java:69)at com.sun.proxy.$Proxy248.getTimestamp(Unknown Source)at org.apache.ibatis.type.DateTypeHandler.getNullableResult(DateTypeHandler.java:39)at org.apache.ibatis.type.DateTypeHandler.getNullableResult(DateTypeHandler.java:28)at org.apache.ibatis.type.BaseTypeHandler.getResult(BaseTypeHandler.java:81)at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.createUsingConstructor(DefaultResultSetHandler.java:671)at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.createByConstructorSignature(DefaultResultSetHandler.java:654)at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.createResultObject(DefaultResultSetHandler.java:618)at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.createResultObject(DefaultResultSetHandler.java:591)at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.getRowValue(DefaultResultSetHandler.java:397)at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleRowValuesForSimpleResultMap(DefaultResultSetHandler.java:354)at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleRowValues(DefaultResultSetHandler.java:328)at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleResultSet(DefaultResultSetHandler.java:301)at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleResultSets(DefaultResultSetHandler.java:194)at org.apache.ibatis.executor.statement.PreparedStatementHandler.query(PreparedStatementHandler.java:65)at org.apache.ibatis.executor.statement.RoutingStatementHandler.query(RoutingStatementHandler.java:79)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)at java.lang.reflect.Method.invoke(Method.java:498)at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:63)at com.sun.proxy.$Proxy236.query(Unknown Source)at com.baomidou.mybatisplus.core.executor.MybatisSimpleExecutor.doQuery(MybatisSimpleExecutor.java:67)at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:324)at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156)at com.baomidou.mybatisplus.core.executor.MybatisCachingExecutor.query(MybatisCachingExecutor.java:155)at com.github.pagehelper.PageInterceptor.intercept(PageInterceptor.java:143)at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:61)at com.sun.proxy.$Proxy235.query(Unknown Source)at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:147)at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:140)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)at java.lang.reflect.Method.invoke(Method.java:498)at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:426)... 37 more
实体类:
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("teacher_question")
@ApiModel(value="TeacherQuestion对象", description="")
public class TeacherQuestion implements Serializable {private static final long serialVersionUID = 1L;@TableId(value = "id", type = IdType.AUTO)private Integer id;@TableField("teacher_id")private Integer teacherId;@TableField("question_id")private Integer questionId;@TableField("createtime")private Date createtime;public TeacherQuestion(Integer teacherId, Integer questionId, Date createtime) {this.teacherId = teacherId;this.questionId = questionId;this.createtime = createtime;}
}
mapper类和mapper文件如下:
public interface TeacherQuestionMapper extends BaseMapper<TeacherQuestion> {}<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.tedu.straw.portal.mapper.TeacherQuestionMapper"><!-- 通用查询映射结果 --><resultMap id="BaseResultMap" type="cn.tedu.straw.portal.model.TeacherQuestion"><id column="id" property="id" /><result column="teacher_id" property="teacherId" /><result column="question_id" property="questionId" /><result column="createtime" property="createtime" /></resultMap></mapper>
数据库表如下:
测试类如下:
@SpringBootTest(classes = StrawPortalApplication.class)
@RunWith(SpringRunner.class)
public class TestTeacherQuestionMapper {@Resourceprivate TeacherQuestionMapper teacherQuestionMapper;@Testpublic void selectOne(){QueryWrapper queryWrapper=new QueryWrapper();queryWrapper.eq("teacher_id",4);queryWrapper.eq("question_id",44);List<TeacherQuestion> teacherQuestions = teacherQuestionMapper.selectList(queryWrapper);System.out.println(teacherQuestions);}}
反复测试了好多次,不管什么测试条件都是报Cause: java.sql.SQLDataException: Unsupported conversion from LONG to java.sql.Timestamp错误。
后来才想起来自己在实体类里加了一个带参数的构造方法:
public TeacherQuestion(Integer teacherId, Integer questionId, Date createtime) {this.teacherId = teacherId;this.questionId = questionId;this.createtime = createtime;}
这样就导致该实体类没有无参构造方法了,众所周知,一旦我们手动添加了带参数的构造方法,编译器就不会给我们添加默认的无参构造方法。导致mybatis无法new这个实体类。也就无法做映射。
解决的办法是:给该实体类手动添加一个无参构造方法。
public TeacherQuestion() {}
Cause java.sql.SQLDataException Unsupported conversion from LONG to java.sql.Timestamp相关推荐
- 【java.sql.SQLDataException】:Unsupported conversion from LONG to java.sql.Timestamp
今天开发需求的时候,遇到一个喜闻乐见的BUG 前台报错如下: 后端报错如下: 翻译翻译: 把Long类型数据转化为Timestamp出错. 定位到错误代码: 嗯,这里的方法已经return了,不是这里 ...
- java.sql.SQLException: Illegal conversion 非法转化
java.sql.SQLException: Illegal conversion 非法转换 当报这个错的时候,很可能是sql查出来的结果的字段类型和实体类的字段类型不一致,导致封装失败,报错
- java.sql.SQLException: Unsupported character encoding 'utf8mb4'.
四月 12, 2017 3:47:52 下午 org.apache.catalina.core.StandardWrapperValve invoke 严重: Servlet.service() fo ...
- java执行sql文件_面试官问你MyBatis SQL是如何执行的?把这篇文章甩给他
初识 MyBatis MyBatis 是第一个支持自定义 SQL.存储过程和高级映射的类持久框架.MyBatis 消除了大部分 JDBC 的样板代码.手动设置参数以及检索结果.MyBatis 能够支持 ...
- Java程序员从笨鸟到菜鸟之(一百)sql注入攻击详解(一)sql注入原理详解
前段时间,在很多博客和微博中暴漏出了12306铁道部网站的一些漏洞,作为这么大的一个项目,要说有漏洞也不是没可能,但其漏洞确是一些菜鸟级程序员才会犯的错误.其实sql注入漏洞就是一个.作为一个菜鸟小程 ...
- java与sql用windows身份连接,使用Windows身份验证将我的Sql Server 2008数据库连接到我的Java项目...
JDBC驱动程序支持通过则将integratedSecurity连接字符串属性在Windows操作系统上使用类型2集成身份验证.要使用集成身份验证,请将sqljdbc_auth.dll文件复制到安装了 ...
- java 中的sql.date_SQL DATE中的时区vs java.sql.Date
小编典典 在JDBC规范不问候时区定义的任何细节.尽管如此,我们大多数人都知道必须处理JDBC时区差异的痛苦. 最终,日期/时间数据库类型的时区处理归结为数据库服务器,JDBC驱动程序以及两者之间的所 ...
- java中将date插入mysql中date_JAVA 处理时间 - java.sql.Date、java.util.Date与数据库中的Date字段的转换方法[转]...
1.如何将java.util.Date转化为java.sql.Date? 转化: java.sql.Date sd; java.util.Date ud; //initialize the ud su ...
- java比较时间sql_如何正确比较日期 java.sql.Date
import java.sql.Date; ..... .... ... .. . 例如今天是2010-12-2 Date d1 = new Date(System.currentTimeMili() ...
最新文章
- python数据分析是什么意思_python数据分析有什么用
- python3 eval代码示例
- crt 8.7.3 黑暗模式_民谣缠绕厄运金属,抒情中的黑暗故事
- python复杂网络点图可视化_Python学习工具:9个用来爬取网络站点的 Python 库
- 【推荐】开源堡垒机Teleport
- java manager 如何使用_java – Android:如何使用AlarmManager
- Node单线程的特点
- 在JavaScript中使用JSON
- switch常用的交换机配置命令
- Android 配置https抓包
- linux sin()编译
- 恶意代码分析平台Truman相关资料
- chapter3 转录组学
- [BUGKU] [MISC]普通的二维码
- 关于龙芯CPU几发射的问题
- 好莱坞明星识别-第六周
- android canvas 工作流_Activiti工作流引擎使用
- 《正点原子嵌入式linux驱动开发指南V1.4》学习笔记
- 【原创】二阶常系数非齐次线性微分方程求特解
- smurf攻击的工作原理