org.postgresql.util.PSQLException: Bad value for type long

项目用 springboot+mybatis +mybatisplus, 数据库是:postgresql执行查询时候返回错误。

org.springframework.dao.DataIntegrityViolationException: Error attempting to get column 'city_id' from result set. Cause: org.postgresql.util.PSQLException: Bad value for type long :
; Bad value for type long : ; nested exception is org.postgresql.util.PSQLException: Bad value for type long

类型long的值不正确

完整错误信息如下

java 复制代码
org.springframework.dao.DataIntegrityViolationException: Error attempting to get column 'city_id' from result set.  Cause: org.postgresql.util.PSQLException: Bad value for type long : 
; Bad value for type long : ; nested exception is org.postgresql.util.PSQLException: Bad value for type long : 
	at org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.doTranslate(SQLStateSQLExceptionTranslator.java:104)
	at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)
	at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)
	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.$Proxy174.selectOne(Unknown Source)
	at org.mybatis.spring.SqlSessionTemplate.selectOne(SqlSessionTemplate.java:159)
	at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.execute(MybatisMapperMethod.java:108)
	at com.baomidou.mybatisplus.core.override.MybatisMapperProxy.invoke(MybatisMapperProxy.java:96)
	at com.sun.proxy.$Proxy204.getUser(Unknown Source)

java对象实体

mybatis mapper XML 文件

java 复制代码
    <resultMap id="BaseResultMap" type="org.vo.UserVO">
        <id column="user_id" property="userId"/>
        <result column="city_id" property="cityId"/>
        <result column="sex" property="sex"/>
        <result column="header" property="header"/>
        <result column="nick_name" property="nickName"/>
        <result column="telphone" property="telphone"/>
        <result column="email" property="email"/>
        <result column="address" property="address"/>
        <result column="birthday" property="birthday"/>
        <result column="real_name" property="realName"/>
        <result column="local_address" property="localAddress"/>
        <result column="create_time" property="createTime"/>
    </resultMap>

    


<select id="getUser" resultMap="BaseResultMap">
        SELECT *
        FROM c_user
        WHERE user_id = #{userId}
    </select>

在数据库中 city_id 是空的。

在mysql是正常的。切换到postgresql 就会提示这样的错。

我把数据为空的字段赋值以后就不报错误了。

解决方案:直接在定义BaseResultMap时候定义字段类型 ResultType="Long"

【注意】一定是大写的Long。Long:用于表示long类型的包装类。long 不能等于null,但是包装类是对象可以为null。

相关推荐
qmx_0716 分钟前
HTB-Jerry(tomcat war文件、msfvenom)
java·web安全·网络安全·tomcat
为风而战24 分钟前
IIS+Ngnix+Tomcat 部署网站 用IIS实现反向代理
java·tomcat
技术无疆2 小时前
快速开发与维护:探索 AndroidAnnotations
android·java·android studio·android-studio·androidx·代码注入
架构文摘JGWZ5 小时前
Java 23 的12 个新特性!!
java·开发语言·学习
拾光师6 小时前
spring获取当前request
java·后端·spring
aPurpleBerry6 小时前
neo4j安装启动教程+对应的jdk配置
java·neo4j
我是苏苏6 小时前
Web开发:ABP框架2——入门级别的增删改查Demo
java·开发语言
xujinwei_gingko6 小时前
Spring IOC容器Bean对象管理-Java Config方式
java·spring
2301_789985946 小时前
Java语言程序设计基础篇_编程练习题*18.29(某个目录下的文件数目)
java·开发语言·学习
IT学长编程7 小时前
计算机毕业设计 教师科研信息管理系统的设计与实现 Java实战项目 附源码+文档+视频讲解
java·毕业设计·springboot·毕业论文·计算机毕业设计选题·计算机毕业设计开题报告·教师科研管理系统