MyBatis - 结果中缺少一些记录

时间:2015-08-06 08:50:49

标签: mapping mybatis discriminator

我有一个结果图:

    <resultMap type="cz.pse.agata.commons.dto.Security" id="detailed_security">
    <result property="id" column="VAID"/>
    <result property="issueId" column="VAIDVA"/>
    <result property="effectiveDate" column="VAEFDT"/>
    <result property="bic" column="VABIC"/>
    .
    .
    .
    <association property="isin" column="VACVAL" javaType="cz.pse.agata.commons.dto.ISIN">
        <result property="isin" column="VACVAL"/>
    </association>
    <association property="legalPerson" javaType="cz.pse.agata.commons.dto.LegalPerson"
            resultMap="legalPerson" columnPrefix="specialist_person_"/>
    </association>  
    <association property="emitent" column="VAEMIT" javaType="cz.pse.agata.commons.dto.LegalPerson"
        resultMap="cz.pse.agata.commons.dto.mapper.LegalPersonMapper.legalPerson"/>
    <association property="administrator" column="VAIDAD" javaType="cz.pse.agata.commons.dto.LegalPerson" 
        resultMap="legalPerson"/>
    <association property="changeReason" column="VAIDCD" javaType="cz.pse.agata.commons.dto.ChangeReason">
        <result property="id" column="CDID"/>
        <result property="reason" column="CDTEXT"/>
    </association>
    <association property="tail" javaType="Object">
         <discriminator javaType="String" column="VATVAL">
            <case value="000" resultType="cz.pse.agata.commons.dto.SecurityTailImpl">
                <result property="issueId" column="VAIDVA"/>
            </case>
            <case value="520" resultType="cz.pse.agata.commons.dto.SecurityTailImpl">
                <result property="issueId" column="VAIDVA"/>
            </case>
            <case value="100" resultMap="cz.pse.cp.dto.mapper.BondMapper.Bond"/>
            <case value="150" resultMap="cz.pse.cp.dto.mapper.BondMapper.Bond"/>
            <case value="200" resultMap="cz.pse.cp.dto.mapper.BondMapper.Bond"/>
            <case value="500" resultType="cz.pse.agata.commons.dto.SecurityTailImpl">
                <result property="issueId" column="VAIDVA"/>
            </case>
            <case value="510" resultType="cz.pse.agata.commons.dto.SecurityTailImpl">
                <result property="issueId" column="VAIDVA"/>
            </case>
            <case value="610" resultMap="cz.pse.cp.dto.mapper.WarrantMapper.Warrant"/>
            <case value="660" resultMap="cz.pse.cp.dto.mapper.WarrantMapper.Warrant">
                <result property="id" column="WAID"/>
            </case>
            <case value="600" resultMap="cz.pse.cp.dto.mapper.InvestementCertificateMapper.InvestementCertificate"/>
            <case value="650" resultMap="cz.pse.cp.dto.mapper.InvestementCertificateMapper.InvestementCertificate"/>
            <case value="300" resultType="cz.pse.agata.commons.dto.SecurityTailImpl">
                <result property="issueId" column="VAIDVA"/>
            </case>
            <case value="305" resultType="cz.pse.agata.commons.dto.SecurityTailImpl">
                <result property="issueId" column="VAIDVA"/>
            </case>
            <case value="400" resultType="cz.pse.agata.commons.dto.SecurityTailImpl">
                <result property="issueId" column="VAIDVA"/>
            </case>
        </discriminator>
    </association>
  </resultMap>

我有一个查询,返回 4 行:

 ==>  Preparing: with dates as ( select vaefdt as dat from ....
 ==> Parameters: 109735(Long), 109735(Long), ....
<==      Total: 4

但结果列表仅包含 3 项目。

经过一些调试后,我意识到它发生了(可能),因为除了 tail 值之外,4行中的2行所有数据都相同:

(方法org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleRowValuesForNestedResultMap(ResultSetWrapper,ResultMap,ResultHandler,RowBounds,ResultMapping))

private void handleRowValuesForNestedResultMap(ResultSetWrapper rsw, ResultMap resultMap, ResultHandler resultHandler, RowBounds rowBounds, ResultMapping parentMapping) throws SQLException { final DefaultResultContext resultContext = new DefaultResultContext(); skipRows(rsw.getResultSet(), rowBounds); Object rowValue = null; while (shouldProcessMoreRows(resultContext, rowBounds) && rsw.getResultSet().next()) { final ResultMap discriminatedResultMap = resolveDiscriminatedResultMap(rsw.getResultSet(), resultMap, null); final CacheKey rowKey = createRowKey(discriminatedResultMap, rsw, null); Object partialObject = nestedResultObjects.get(rowKey); // issue #577 && #542 if (mappedStatement.isResultOrdered()) { if (partialObject == null && rowValue != null) { nestedResultObjects.clear(); storeObject(resultHandler, resultContext, rowValue, parentMapping, rsw.getResultSet()); } rowValue = getRowValue(rsw, discriminatedResultMap, rowKey, rowKey, null, partialObject); } else { rowValue = getRowValue(rsw, discriminatedResultMap, rowKey, rowKey, null, partialObject); if (partialObject == null) { storeObject(resultHandler, resultContext, rowValue, parentMapping, rsw.getResultSet()); } } } if (rowValue != null && mappedStatement.isResultOrdered() && shouldProcessMoreRows(resultContext, rowBounds)) { storeObject(resultHandler, resultContext, rowValue, parentMapping, rsw.getResultSet()); } }

注意上面的粗体文字:对于第二次迭代,创建了正确的 rowValue ,但它没有添加到结果中,因为 partialObject 不为空。

任何帮助都将不胜感激。

0 个答案:

没有答案