Brief problem description
Following guideline for multiple resultsets and with help from this answer I now able to extract 2 different recordsets but they are just list and do not mapped on result object.
In details
I have classes (simplified):
public class SupplyChain{
private String id;
private List<SupplyChainNode> nodes;
private List<SupplyChainEdge> edges;
}
public class SupplyChainNode {
private String id;
private String label;
}
public class SupplyChainEdge {
private String id;
private String label;
}
MyBatis
interface declared like:
public interface SupplyChainMBDao {
List<SupplyChain> getByPartyId(@Param("partyId") String partyId);
}
And MyBatis
mapping:
<mapper namespace="ru.rlh.egais.portal.backend.dao.mybatis.SupplyChainMBDao">
<select id="getByPartyId" resultSets="edges,nodes" resultMap="supplyChainMapEdge, supplyChainMapNode"><![CDATA[
-- There big query returns 2 recordset - first for Edges and second for Nodes. They have different amount of rows and logic of obtain, but share initial computation and it is desire to return them atomic.
-- Let it be for simplicity:
SELECT * FROM (VALUES(1, 2)) edges(id, label);
SELECT * FROM (VALUES(2, 3), (4, 5)) nodes(id, label)
]]></select>
<resultMap id="supplyChainMapEdge" type="ru.rlh.egais.portal.api.dto.bo.supplychain.SupplyChainEdge" >
<result property="label" column="label"/>
</resultMap>
<resultMap id="supplyChainMapNode" type="ru.rlh.egais.portal.api.dto.bo.supplychain.SupplyChainNode" >
<result property="label" column="label"/>
</resultMap>
</mapper>
So, basically it works and I got 2 collections. But instead of declared List<SupplyChain>
return value I really got List<List>
where inner list contain 2 elements in runtime:
- 0 element is
List<SupplyChainEdge>
- and 1st:
List<SupplyChainNode>
.
How to I can wrap this raw collections into object SupplyChain
?