mybatis-3 icon indicating copy to clipboard operation
mybatis-3 copied to clipboard

mybatis get LimitSegment.rowCount incorrectly

Open riceorfreedom opened this issue 3 years ago • 3 comments

MyBatis version

3.4.6

Database vendor and version

mysql 5.6.16-log mysql.connector.version 8.0.11

Test case or example project

CREATE TABLE TABLE_DEMO
(
  id bigint auto_increment comment '主键 ID' primary key,
  shop_lng varchar(32) null comment '店铺经度',
  shop_lat varchar(32) null comment '店铺纬度',
);
INSERT INTO TABLE_DEMO (id, shop_lng,shop_lat) VALUES (1, '120.003446','30.280146');
List<Map<String, Object>> query(
  @Param(value = "maxLng") BigDecimal maxLng,
  @Param(value = "minLng") BigDecimal minLng,
  @Param(value = "maxLat") BigDecimal maxLat,
  @Param(value = "minLat") BigDecimal minLat,
  @Param(value = "limitSize") Integer limitSize);
select id, shop_lng,shop_lat from table_demo where 
CAST(t.shop_lng AS DECIMAL(10,6))<= #{maxLng,jdbcType=DECIMAL}
    and
    CAST(t.shop_lng AS DECIMAL(10,6))>= #{minLng,jdbcType=DECIMAL}
    and
    CAST(t.shop_lat AS DECIMAL(10,6))<= #{maxLat,jdbcType=DECIMAL}
    and
    CAST(t.shop_lat AS DECIMAL(10,6))>= #{minLat,jdbcType=DECIMAL}
    limit #{limitSize}

Steps to reproduce

public List<Map<String, Object>> query() {
  List<ShippingShopGeoInfo> list = mapper.query(
	new BigDecima("120.003446"),new BigDecimal("120.003446"),new BigDecimal("30.280146"),new BigDecimal("30.280146"),100
  );
  return list;
}

Expected result

result: [{id: 1, "shopLng": "120.003446","shopLat": "30.280146"}]

Actual result

org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: java.lang.ClassCastException: java.math.BigDecimal cannot be cast to java.lang.Integer

riceorfreedom avatar Nov 27 '20 06:11 riceorfreedom

please check you paramterType is right if you follow you paramterType like that :

<select id="query" resultType="map" parameterType="int">
 </select>

this will throw java.math.BigDecimal cannot be cast to java.lang.Integer

  1. how to fix: remove parameterType="int"

lonecloud avatar Nov 29 '20 15:11 lonecloud

please check you paramterType is right if you follow you paramterType like that :

<select id="query" resultType="map" parameterType="int">
 </select>

this will throw java.math.BigDecimal cannot be cast to java.lang.Integer

  1. how to fix: remove parameterType="int"

but in actually,I use the param annotation inject params.,so I didn't write the paramterType , and if i use "$" to fill the limit, it can output a expected result

riceorfreedom avatar Nov 30 '20 02:11 riceorfreedom

Hello @riceorfreedom ,

I couldn't reproduce it. Please provide it as an executable project like these and share it on your GitHub repo.

harawata avatar Dec 27 '20 18:12 harawata

No response. Closing.

harawata avatar Mar 08 '23 23:03 harawata