column property mapping overwriten in sub resultmap (extends a base resultmap)

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

column property mapping overwriten in sub resultmap (extends a base resultmap)

Jolyon Zhou
I have the xml config:

<resultMap id="A">
    <result column="MY_NAME" property="myName" />
</resultMap>

<resultMap id="B" extends="A">
    <result column="MY_NAME" property="myName2" />
</resultMap>

But actually when I use resultMap B, the value of column MY_NAME is always assigned to property myName. (I expect it to go to myName2)
The overwrite does not work.

Of course I can write the xml config like this to get it work:

<resultMap id="B" extends="A">
    <result column="MY_NAME2" property="myName2" />
</resultMap>
<select resultMap="B">
select MY_NAME as MY_NAME2 ......
</select>

I looked into the code of v3.3.0 and v3.4.5, it seems the author have not consider that kind of case.

What is the real reason? Not considered ? Or should not? Or just not important?

Thanks.


--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: column property mapping overwriten in sub resultmap (extends a base resultmap)

Erwan Letessier
Result maps here are XML entities and I guess that unlike java classes, extends only allows extending: additional column mapping but no overriding. Indeed the behavior is not what you expected.
I suppose a column is mapped to only 1 property and other mapping for this column is ignored.
You could avoid altering query by defining a 3rd result map with all common mapping. A and B extending it with specific.
Cheers 

On Jan 18, 2018 14:21, "Jolyon Zhou" <[hidden email]> wrote:
I have the xml config:

<resultMap id="A">
    <result column="MY_NAME" property="myName" />
</resultMap>

<resultMap id="B" extends="A">
    <result column="MY_NAME" property="myName2" />
</resultMap>

But actually when I use resultMap B, the value of column MY_NAME is always assigned to property myName. (I expect it to go to myName2)
The overwrite does not work.

Of course I can write the xml config like this to get it work:

<resultMap id="B" extends="A">
    <result column="MY_NAME2" property="myName2" />
</resultMap>
<select resultMap="B">
select MY_NAME as MY_NAME2 ......
</select>

I looked into the code of v3.3.0 and v3.4.5, it seems the author have not consider that kind of case.

What is the real reason? Not considered ? Or should not? Or just not important?

Thanks.


--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: column property mapping overwriten in sub resultmap (extends a base resultmap)

Jolyon Zhou

Thanks. I agree with you.
Maybe later an "override" attribute could be added as follows :)

<resultMap id="B" extends="A">
    <result column="MY_NAME" property="myName2" override="true" />
</resultMap>


On Thursday, January 18, 2018 at 3:48:00 PM UTC+8, Erwan Letessier wrote:
Result maps here are XML entities and I guess that unlike java classes, extends only allows extending: additional column mapping but no overriding. Indeed the behavior is not what you expected.
I suppose a column is mapped to only 1 property and other mapping for this column is ignored.
You could avoid altering query by defining a 3rd result map with all common mapping. A and B extending it with specific.
Cheers 

On Jan 18, 2018 14:21, "Jolyon Zhou" <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="V2aWAUtEFAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">zzl...@...> wrote:
I have the xml config:

<resultMap id="A">
    <result column="MY_NAME" property="myName" />
</resultMap>

<resultMap id="B" extends="A">
    <result column="MY_NAME" property="myName2" />
</resultMap>

But actually when I use resultMap B, the value of column MY_NAME is always assigned to property myName. (I expect it to go to myName2)
The overwrite does not work.

Of course I can write the xml config like this to get it work:

<resultMap id="B" extends="A">
    <result column="MY_NAME2" property="myName2" />
</resultMap>
<select resultMap="B">
select MY_NAME as MY_NAME2 ......
</select>

I looked into the code of v3.3.0 and v3.4.5, it seems the author have not consider that kind of case.

What is the real reason? Not considered ? Or should not? Or just not important?

Thanks.


--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="V2aWAUtEFAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">mybatis-user...@googlegroups.com.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.