首页 > 解决方案 > MyBatis 嵌套选择为空白,带有 UUID 输入参数

问题描述

我的 MyBatis 关联通过嵌套选择返回一个空的结果集。

传递给嵌套选择的参数是来自 Oracle 数据库中 RAW 数据类型列的 UUID。

您可以在下面看到,我正在尝试将“cfg_one_key”列值传递给嵌套选择,以匹配嵌套选择查询中名称略有不同的列 (cfg_one_pk)。

我没有看到任何错误,但我没有得到任何结果。当我使用 DB 可视化应用程序直接查询数据库时,我看到了一个结果。

所以,我想知道是否不能使用 UUID 值进行嵌套选择?


    <resultMap id="cfgsMap" type="Cfgs">
      <association property="cfgOne" javaType="CfgOne">
        <id property="cfgOneKey" column="cfg_one_key"/>
        <result property="cfgOneLabel" column="cfg_one_label"/>
        <result property="cfgOneLastModified" column="cfg_one_last_modified"/>
      </association>
      <collection property="cfgTwo" column="cfg_one_key" ofType="CfgTwo" select="selectCfgTwo"/>
    </resultMap>

    <select id="selectCfgOne" resultMap="cfgsMap">
        SELECT cfg_one_key, cfg_one_label, cfg_one_last_modified
        FROM cfg_one
        WHERE is_latest = 'Y' AND cfg_one_label = 'Dummy Config'
    </select>

    <select id="selectCfgTwo" resultType="CfgTwo">
        SELECT cfg_two_key, cfg_two_label, cfg_two_last_modified
        FROM cfg_two
        WHERE cfg_one_pk = #{cfg_one_key}
    </select>

标签: springmybatis

解决方案


推荐阅读