栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Oracle数据库LocalDateTime在Mybatis-plus报错:无效列类型

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Oracle数据库LocalDateTime在Mybatis-plus报错:无效列类型

oracle版本:11.2.0.4.0

pom依赖:

         
        
            com.oracle.database.jdbc
            ojdbc6
            11.2.0.4
        
         
        
            com.alibaba
            druid-spring-boot-starter
            1.2.5
        
        
        
            com.baomidou
            mybatis-plus-boot-starter
            3.4.2
        

实体类:

@Data
@TableName("TEST")
@ApiModel(value="Test对象", description="测试date")
public class Test implements Serializable {
    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "id")
    @TableId
    private Long id;

    @ApiModelProperty(value = "创建日期")
    @TableField(fill = FieldFill.INSERT)
    private LocalDateTime createTime;

    @ApiModelProperty(value = "开始时间")
    private LocalTime startTime;

    @ApiModelProperty(value = "名称")
    private String name;
}

主要报错信息:

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.time.LocalDateTime, jdbcType=null, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}. Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #2 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: java.sql.SQLException: 无效的列类型
	
Caused by: org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='createTime', mode=IN, javaType=class java.time.LocalDateTime, jdbcType=null, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}. Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #2 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: java.sql.SQLException: 无效的列类型
	at com.baomidou.mybatisplus.core.MybatisDefaultParameterHandler.setParameters(MybatisDefaultParameterHandler.java:233)
	at org.apache.ibatis.executor.statement.PreparedStatementHandler.parameterize(PreparedStatementHandler.java:94)
	at org.apache.ibatis.executor.statement.RoutingStatementHandler.parameterize(RoutingStatementHandler.java:64)
	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.$Proxy319.parameterize(Unknown Source)
	at com.baomidou.mybatisplus.core.executor.MybatisSimpleExecutor.prepareStatement(MybatisSimpleExecutor.java:97)
	at com.baomidou.mybatisplus.core.executor.MybatisSimpleExecutor.doUpdate(MybatisSimpleExecutor.java:53)
	at org.apache.ibatis.executor.baseExecutor.update(baseExecutor.java:117)
	at com.baomidou.mybatisplus.core.executor.MybatisCachingExecutor.update(MybatisCachingExecutor.java:83)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:197)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:184)
	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)
	... 100 common frames omitted
Caused by: org.apache.ibatis.type.TypeException: Error setting non null for parameter #2 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: java.sql.SQLException: 无效的列类型
	at org.apache.ibatis.type.baseTypeHandler.setParameter(baseTypeHandler.java:71)
	at com.baomidou.mybatisplus.core.MybatisDefaultParameterHandler.setParameters(MybatisDefaultParameterHandler.java:231)
	... 119 common frames omitted
Caused by: java.sql.SQLException: 无效的列类型
	at oracle.jdbc.driver.OraclePreparedStatement.setObjectCritical(OraclePreparedStatement.java:8921)
	at oracle.jdbc.driver.OraclePreparedStatement.setObjectInternal(OraclePreparedStatement.java:8396)
	at oracle.jdbc.driver.OraclePreparedStatement.setObjectInternal(OraclePreparedStatement.java:9176)
	at oracle.jdbc.driver.OraclePreparedStatement.setObject(OraclePreparedStatement.java:9153)
	at oracle.jdbc.driver.OraclePreparedStatementWrapper.setObject(OraclePreparedStatementWrapper.java:234)
	at com.alibaba.druid.filter.FilterChainImpl.preparedStatement_setObject(FilterChainImpl.java:3453)
	at com.alibaba.druid.filter.FilterAdapter.preparedStatement_setObject(FilterAdapter.java:1321)
	at com.alibaba.druid.filter.FilterChainImpl.preparedStatement_setObject(FilterChainImpl.java:3450)
	at com.alibaba.druid.filter.FilterAdapter.preparedStatement_setObject(FilterAdapter.java:1321)
	at com.alibaba.druid.filter.FilterChainImpl.preparedStatement_setObject(FilterChainImpl.java:3450)
	at com.alibaba.druid.proxy.jdbc.PreparedStatementProxyImpl.setObject(PreparedStatementProxyImpl.java:460)
	at com.alibaba.druid.pool.DruidPooledPreparedStatement.setObject(DruidPooledPreparedStatement.java:480)
	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.PreparedStatementLogger.invoke(PreparedStatementLogger.java:67)
	at com.sun.proxy.$Proxy321.setObject(Unknown Source)
	at org.apache.ibatis.type.LocalDateTimeTypeHandler.setNonNullParameter(LocalDateTimeTypeHandler.java:33)
	at org.apache.ibatis.type.LocalDateTimeTypeHandler.setNonNullParameter(LocalDateTimeTypeHandler.java:28)
	at org.apache.ibatis.type.baseTypeHandler.setParameter(baseTypeHandler.java:69)
	... 120 common frames omitted

网上也看了其它同学的帖子:Springboot Mybatis-plus Druid Oracle LocalDateTime转换异常_柏伦-CSDN博客地址其中主流解决方案是:

  1. 换连接池
  2. LocalDateTime改为Date。
  3. Druid改为1.1.21 同时将MybatisPlus版本为3.0.1

但是照做后,并没有解决问题。猜测数据类型在哪一层不匹配,就做了多方尝试,指定mp映射数据类型,不行;换oracle驱动版本到ojdbc7,也不行;又大胆试了一下ojdbc8,竟然成功了。


    com.oracle.database.jdbc
    ojdbc8
    21.3.0.0

由此,我推测oracle后续的驱动版本不再是固定对应oracle版本,而是可以向后兼容的了。

比较有意思的是:oracle中没有time类型,所以新增LocalTime类型时增进去的是1970-01-01的时间。

新增时参数:

{
	"name": "无可奈何花落去",
	"startTime": "12:12:12"
}

数据库里:

还有一点要注意:需要加入字符集支持,否则查询时要报错

Caused by: java.sql.SQLException: 不支持的字符集 (在类路径中添加 orai18n.jar): ZHS16GBK
	at oracle.sql.CharacterSetUnknown.failCharsetUnknown(CharacterSetFactoryThin.java:233)
	at oracle.sql.CharacterSetUnknown.convert(CharacterSetFactoryThin.java:194)
	at oracle.jdbc.driver.PhysicalConnection.throughDbCharset(PhysicalConnection.java:10365)
	at oracle.jdbc.driver.PhysicalConnection.enquoteIdentifier(PhysicalConnection.java:10442)
	at oracle.jdbc.driver.OracleStatement.enquoteIdentifier(OracleStatement.java:6452)

字符集支持pom:

        
            com.oracle.database.nls
            orai18n
            21.3.0.0
        

成功查询结果:

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/644068.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号