I have a query of MySQL5.7 that returns 2 results if manually executed, but only 1 results if executed via MyBatis (mybatis-spring-boot-starter:2.1.0). So it seems one gets lost somewhere and I don't know why.
I suspect it has something to do with that there doesn't exist an unique identifier in my resultmap, but in my table duplicates are allowed and these should also be returned.
ResultMap:
<resultMap id="orderLocationMap" type="com.me.domain.model.OrderLocation" >
<result property="orderId" column="order_id" />
<result property="createdAt" column="created_at" />
<result property="orderStatus" column="order_status"/>
<result property="skuCode" column="sku_code" />
<result property="orderCount" column="order_count" />
<result property="location" column="location" />
</resultMap>
Select:
SELECT
order_id
,orders.created_at as created_at
,order_status
,order_details.sku_code as sku_code
,order_count
,location
FROM locations
INNER JOIN orders ON locations.order_id = orders.order_id
INNER JOIN order_details ON order_details.sku_code = locations.sku_code
AND order_details.order_id = locations.order_id
AND order_details.line_no = locations.line_no
WHERE order_status = "allocated"
Data(orders) on MySQL5.7:
| order_id(PK) | order_number | order_status | created_at |
|---|---|---|---|
| 1 | 0001-1 | allocated | 2020-09-21 16:14:00 |
Data(orders_details) on MySQL5.7:
| order_detail_id(PK) | order_number | sku_code(FK) | order_count | line_no | created_at |
|---|---|---|---|---|---|
| 1 | 0001-1 | skuAAA | 1 | 1 | 2020-09-21 13:04:00 |
| 2 | 0001-1 | skuAAA | 1 | 2 | 2020-09-21 16:14:00 |
Data(locations) on MySQL5.7:
| location_id(PK) | order_number | sku_code(FK) | allocated_count | line_no | created_at |
|---|---|---|---|---|---|
| 1 | 0001-1 | skuAAA | 1 | 1 | 2020-09-21 13:04:00 |
| 2 | 0001-1 | skuAAA | 1 | 2 | 2020-09-21 16:14:00 |