簡単な問題の説明
複数の結果セットのガイドラインに従い、この回答の助けを借りて、2 つの異なるレコードセットを抽出できるようになりましたが、それらは単なるリストであり、結果オブジェクトにマップされません。
詳細に
クラスがあります(簡略化):
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
次のように宣言されたインターフェース:
public interface SupplyChainMBDao {
List<SupplyChain> getByPartyId(@Param("partyId") String partyId);
}
そしてMyBatis
マッピング:
<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>
したがって、基本的には機能し、2 つのコレクションを取得しました。しかし、宣言された戻り値の代わりに、実行時に内部リストに2つの要素が含まれている場所List<SupplyChain>
を実際に取得しました:List<List>
- 0要素は
List<SupplyChainEdge>
- と 1 番目:
List<SupplyChainNode>
.
この生のコレクションをオブジェクトにラップするにはどうすればよいSupplyChain
ですか?