前情概要
Java实体类字段类型为LocalDateTime
查询sql为
select now();
问题
将now()的值映射给LocalDateTime类型字段时提示如下异常
Cannot convert the column of type TIMESTAMPTZ to requested type timestamp
分析
mybatis里LocalDateTime类型数据是从timestamp转换来的,但在人大金仓/pgsql里面,now()
函数得到的并不是一个单纯的时间戳,而是带时区的时间戳,也就是pgsql里的 TIMESTAMPTZ
类型。
这就会导致 TIMESTAMPTZ
无法正常映射到LocalDateTime。
解决方案
将 select now();
替换为 select now()::timestamp;