Let me ask you a question about <id> tag in <resultMap>.

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

Let me ask you a question about <id> tag in <resultMap>.

Kouhei Toki
Hi,

Let me ask you a question about <id> tag in <resultMap>.

I wrote mapping like below.

<resultMap id="fooResultMap" type="Foo" >
  <result column="NAME" property="name" jdbcType="VARCHAR" />
  <association property="bar" resultMap="barResultMap" />
</resultMap>

When I get 2 record of same value of NAME colmun, mybatis return only 1 Foo object. I want 2 Foo object becouse bar's column is different.

So, I workaround below.

<resultMap id="fooResultMap" type="Foo" >
  <id column="DUMMY_COLUMN_FOR_UNIQUE" />
  <result column="NAME" property="name" jdbcType="VARCHAR" />
  <association property="bar" resultMap="barResultMap" />
</resultMap>

I added <id> tag in <resultMap> and "DUMMY_COLUMN_FOR_UNIQUE" column is dummy(not exists). I successfully got 2 Foo object.

I suppose dummy column result in null, and mybatis probably handle null value as different record. 

Is this behaviour correct and safe ?

Thank you,
Kouhei

--
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: Let me ask you a question about <id> tag in <resultMap>.

Iwao AVE!
Hi Kouhei,

Is this behaviour correct and safe ?

I doubt it.
I usually recommend using row number as the dummy id.

Hope this helps,
Iwao


2017-12-06 0:27 GMT+09:00 Kouhei Toki <[hidden email]>:
Hi,

Let me ask you a question about <id> tag in <resultMap>.

I wrote mapping like below.

<resultMap id="fooResultMap" type="Foo" >
  <result column="NAME" property="name" jdbcType="VARCHAR" />
  <association property="bar" resultMap="barResultMap" />
</resultMap>

When I get 2 record of same value of NAME colmun, mybatis return only 1 Foo object. I want 2 Foo object becouse bar's column is different.

So, I workaround below.

<resultMap id="fooResultMap" type="Foo" >
  <id column="DUMMY_COLUMN_FOR_UNIQUE" />
  <result column="NAME" property="name" jdbcType="VARCHAR" />
  <association property="bar" resultMap="barResultMap" />
</resultMap>

I added <id> tag in <resultMap> and "DUMMY_COLUMN_FOR_UNIQUE" column is dummy(not exists). I successfully got 2 Foo object.

I suppose dummy column result in null, and mybatis probably handle null value as different record. 

Is this behaviour correct and safe ?

Thank you,
Kouhei

--
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: Let me ask you a question about <id> tag in <resultMap>.

Kouhei Toki
Hi Iwao,

Thank you for replay.

> I usually recommend using row number as the dummy id.

In this case, can I omit property attribute of <id> tag and adding row number property to Java class ?

Thanks,
Kouhei

On Thursday, December 7, 2017 at 12:46:55 AM UTC+9, Iwao AVE! wrote:
Hi Kouhei,

Is this behaviour correct and safe ?

I doubt it.
I usually recommend using row number as the dummy id.

Hope this helps,
Iwao


2017-12-06 0:27 GMT+09:00 Kouhei Toki <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="Ka_ovMq8AQAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">kouhe...@...>:
Hi,

Let me ask you a question about <id> tag in <resultMap>.

I wrote mapping like below.

<resultMap id="fooResultMap" type="Foo" >
  <result column="NAME" property="name" jdbcType="VARCHAR" />
  <association property="bar" resultMap="barResultMap" />
</resultMap>

When I get 2 record of same value of NAME colmun, mybatis return only 1 Foo object. I want 2 Foo object becouse bar's column is different.

So, I workaround below.

<resultMap id="fooResultMap" type="Foo" >
  <id column="DUMMY_COLUMN_FOR_UNIQUE" />
  <result column="NAME" property="name" jdbcType="VARCHAR" />
  <association property="bar" resultMap="barResultMap" />
</resultMap>

I added <id> tag in <resultMap> and "DUMMY_COLUMN_FOR_UNIQUE" column is dummy(not exists). I successfully got 2 Foo object.

I suppose dummy column result in null, and mybatis probably handle null value as different record. 

Is this behaviour correct and safe ?

Thank you,
Kouhei

--
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="Ka_ovMq8AQAJ" 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.
Reply | Threaded
Open this post in threaded view
|

Re: Let me ask you a question about <id> tag in <resultMap>.

Iwao AVE!
Yes, you can omit 'property' attribute from <id>.
And you don't need to add row number property to the java class.

Basically, you need to modify the query to include row number in the column list ...

select ROW_NUMBER() OVER() as ROWNUM, NAME, ...
(the syntax depends on the database in use)

... and specify the column in the 'column' attribute of <id>.

<resultMap id="fooResultMap" type="Foo" >
  <id column="ROWNUM" />
  <result column="NAME" property="name" />
  <association property="bar" resultMap="barResultMap" />
</resultMap>

Regards,
Iwao

2017-12-07 8:44 GMT+09:00 Kouhei Toki <[hidden email]>:
Hi Iwao,

Thank you for replay.

> I usually recommend using row number as the dummy id.

In this case, can I omit property attribute of <id> tag and adding row number property to Java class ?

Thanks,
Kouhei

On Thursday, December 7, 2017 at 12:46:55 AM UTC+9, Iwao AVE! wrote:
Hi Kouhei,

Is this behaviour correct and safe ?

I doubt it.
I usually recommend using row number as the dummy id.

Hope this helps,
Iwao


2017-12-06 0:27 GMT+09:00 Kouhei Toki <[hidden email]>:
Hi,

Let me ask you a question about <id> tag in <resultMap>.

I wrote mapping like below.

<resultMap id="fooResultMap" type="Foo" >
  <result column="NAME" property="name" jdbcType="VARCHAR" />
  <association property="bar" resultMap="barResultMap" />
</resultMap>

When I get 2 record of same value of NAME colmun, mybatis return only 1 Foo object. I want 2 Foo object becouse bar's column is different.

So, I workaround below.

<resultMap id="fooResultMap" type="Foo" >
  <id column="DUMMY_COLUMN_FOR_UNIQUE" />
  <result column="NAME" property="name" jdbcType="VARCHAR" />
  <association property="bar" resultMap="barResultMap" />
</resultMap>

I added <id> tag in <resultMap> and "DUMMY_COLUMN_FOR_UNIQUE" column is dummy(not exists). I successfully got 2 Foo object.

I suppose dummy column result in null, and mybatis probably handle null value as different record. 

Is this behaviour correct and safe ?

Thank you,
Kouhei

--
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 mybatis-user...@googlegroups.com.
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.

--
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: Let me ask you a question about <id> tag in <resultMap>.

Kouhei Toki
Hi Iwao,

Thank you so much.
I succesfully handled using row number.
I am using mysql and sql is complex (group by, union, etc...)  and written by other people.
So, I wraped original sql like below.

select @rownum:=@rownum+1 as rownum, org.* from (
### original sql ###
) org, (select @rownum:=0) r

I hope this will help someone using mysql.

Thanks,
Kouhei


On Saturday, December 9, 2017 at 12:42:53 AM UTC+9, Iwao AVE! wrote:
Yes, you can omit 'property' attribute from <id>.
And you don't need to add row number property to the java class.

Basically, you need to modify the query to include row number in the column list ...

select ROW_NUMBER() OVER() as ROWNUM, NAME, ...
(the syntax depends on the database in use)

... and specify the column in the 'column' attribute of <id>.

<resultMap id="fooResultMap" type="Foo" >
  <id column="ROWNUM" />
  <result column="NAME" property="name" />
  <association property="bar" resultMap="barResultMap" />
</resultMap>

Regards,
Iwao

2017-12-07 8:44 GMT+09:00 Kouhei Toki <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="M5SHdbtZAgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">kouhe...@...>:
Hi Iwao,

Thank you for replay.

> I usually recommend using row number as the dummy id.

In this case, can I omit property attribute of <id> tag and adding row number property to Java class ?

Thanks,
Kouhei

On Thursday, December 7, 2017 at 12:46:55 AM UTC+9, Iwao AVE! wrote:
Hi Kouhei,

Is this behaviour correct and safe ?

I doubt it.
I usually recommend using row number as the dummy id.

Hope this helps,
Iwao


2017-12-06 0:27 GMT+09:00 Kouhei Toki <[hidden email]>:
Hi,

Let me ask you a question about <id> tag in <resultMap>.

I wrote mapping like below.

<resultMap id="fooResultMap" type="Foo" >
  <result column="NAME" property="name" jdbcType="VARCHAR" />
  <association property="bar" resultMap="barResultMap" />
</resultMap>

When I get 2 record of same value of NAME colmun, mybatis return only 1 Foo object. I want 2 Foo object becouse bar's column is different.

So, I workaround below.

<resultMap id="fooResultMap" type="Foo" >
  <id column="DUMMY_COLUMN_FOR_UNIQUE" />
  <result column="NAME" property="name" jdbcType="VARCHAR" />
  <association property="bar" resultMap="barResultMap" />
</resultMap>

I added <id> tag in <resultMap> and "DUMMY_COLUMN_FOR_UNIQUE" column is dummy(not exists). I successfully got 2 Foo object.

I suppose dummy column result in null, and mybatis probably handle null value as different record. 

Is this behaviour correct and safe ?

Thank you,
Kouhei

--
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 mybatis-user...@googlegroups.com.
For more options, visit <a href="https://groups.google.com/d/optout" rel="nofollow" target="_blank" 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 <a href="javascript:" target="_blank" gdf-obfuscated-mailto="M5SHdbtZAgAJ" 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.