一次java bean与sql查询的奇怪踩坑

在业务开发中,写了一个BO类,如下:

@Data
@Builder
public class Division {
private Integer provinceCode;
private Integer cityCode;
private Integer areaCode;
private String province;
private String city;
private String area;
}

这个类通过查询sql获得对应的参数,如下:
<resultMap id="BaseResultMap" type="bo.Division">
<result column="area_id" property="areaCode"/>
<result column="province_id" property="provinceCode"/>
<result column="province" property="province"/>
<result column="city_id" property="cityCode"/>
<result column="city" property="city"/>
<result column="area" property="area"/>
</resultMap>
<select id="getDivisionByAreaCode" resultMap="BaseResultMap">
select area.area_id,area.area,city.city_id,city.city,province.province_id,province.province from area
LEFT JOIN city ON area.father_id = city.city_id
LEFT JOIN province ON city.father_id = province.province_id
where area.area_id = #{areaCode}
</select>

但是在查询时,某些数据会报错,提示如下:

Error attempting to get column ‘area‘ from result set. Cause: java.sql.SQLDataException: Cannot determine value type from string ‘白云区‘
; Cannot determine value type from string ‘白云区‘

一次java bean与sql查询的奇怪踩坑

百度了半天,没有找到原因,后来搜索Cannot determine value type from string 这类报错,有出坑的的说是缺少了无参构造,于是修改类如下:

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Division {
private Integer provinceCode;
private Integer cityCode;
private Integer areaCode;
private String province;
private String city;
private String area;
}

补充了全参数构造与无参数构造,然后,好了?不是很明白这个是什么情况,查询数据库与有参数无参数有关系吗?

一次java bean与sql查询的奇怪踩坑

上一篇:Oracle第一课


下一篇:HTTP压力测试工具