• 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的值不正确

    完整错误信息如下

    1. org.springframework.dao.DataIntegrityViolationException: Error attempting to get column 'city_id' from result set. Cause: org.postgresql.util.PSQLException: Bad value for type long :
    2. ; Bad value for type long : ; nested exception is org.postgresql.util.PSQLException: Bad value for type long :
    3. at org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.doTranslate(SQLStateSQLExceptionTranslator.java:104)
    4. at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)
    5. at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)
    6. at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)
    7. at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:88)
    8. at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:440)
    9. at com.sun.proxy.$Proxy174.selectOne(Unknown Source)
    10. at org.mybatis.spring.SqlSessionTemplate.selectOne(SqlSessionTemplate.java:159)
    11. at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.execute(MybatisMapperMethod.java:108)
    12. at com.baomidou.mybatisplus.core.override.MybatisMapperProxy.invoke(MybatisMapperProxy.java:96)
    13. at com.sun.proxy.$Proxy204.getUser(Unknown Source)

    java对象实体

    mybatis mapper XML 文件

    1. "BaseResultMap" type="org.vo.UserVO">
    2. "user_id" property="userId"/>
    3. "city_id" property="cityId"/>
    4. "sex" property="sex"/>
    5. "header" property="header"/>
    6. "nick_name" property="nickName"/>
    7. "telphone" property="telphone"/>
    8. "email" property="email"/>
    9. "address" property="address"/>
    10. "birthday" property="birthday"/>
    11. "real_name" property="realName"/>
    12. "local_address" property="localAddress"/>
    13. "create_time" property="createTime"/>

    数据库中 city_id 是空的。

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

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

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

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

  • 相关阅读:
    昨天步行的思考
    BUUCTF Reverse/crackMe
    深入探求:中国精益生产与管理实践的崭新视角
    使用Golang策略和最佳实践高效处理一百万个请求
    IDEA 开发 SparkSQL
    Oracle/PLSQL: Cos Function
    Xilinx cache刷新使用的问题
    ElasticSearch集群内存占用高?如何降低内存占用看这篇文章就够啦!(冻结索引)
    BAPI 和 RFC 的区别
    以数助实攻坚产业协作 蚂蚁集团数字科技业务亮相云栖大会
  • 原文地址:https://blog.csdn.net/wochunyang/article/details/133132828