TypeHandler is not called in association (nested select)

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

TypeHandler is not called in association (nested select)

Ludovic Heitz
Hello group,

I'm not sure if I found a bug or if I miss something.
I'm working with MyBatis 3.2.8.

I create an implementation of org.apache.ibatis.type.TypeHandler (called MyTypeHandler) to map a Long to a custom type (let's say MyType).

In my first DAO, I got a method like this: Long getLong(Integer).
In a second DAO, I invoke the previous method inside an <association>:

<resultMap...>
    ...
    <association property="myProperty" javaType="MyType" column="SOME_VALUE" select="FirstDao.getLong" typeHandler="MyTypeHandler"/>
</resultMap>

Looking at the logs, it see the query execution of FirstDao.getLong, but then my type handler is never reached.
Though, documentation references the typeHandler attribute for the <association> element.
Please note that I am able to use my type handler with a <result> element.
The problem occurs with an <association>.

Thanks for attention
Ludovic

--
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: TypeHandler is not called in association (nested select)

Iwao AVE!

Hi Ludovic,

Type handler is not used when mapping association.
It is used when building the result of the nested select.

So, you may need to register the type handler in the config.

<typeHandlers>
  <typeHandler
    javaType="MyType" 
    handler="MyTypeHandler"/>
</typeHandlers>

and specify MyType as resultType of the nested query.

<select id="getLong" resultType="MyType">
  select TYPE_COL
  from TYPE_TBL where ...
</select>

The association is pretty simple.

<association
  property="myProperty"
  column="SOME_VALUE"
  select="FirstDao.getLong" />

Regards,
Iwao

2017-04-20 17:20 GMT+09:00 Ludovic Heitz <[hidden email]>:
Hello group,

I'm not sure if I found a bug or if I miss something.
I'm working with MyBatis 3.2.8.

I create an implementation of org.apache.ibatis.type.TypeHandler (called MyTypeHandler) to map a Long to a custom type (let's say MyType).

In my first DAO, I got a method like this: Long getLong(Integer).
In a second DAO, I invoke the previous method inside an <association>:

<resultMap...>
    ...
    <association property="myProperty" javaType="MyType" column="SOME_VALUE" select="FirstDao.getLong" typeHandler="MyTypeHandler"/>
</resultMap>

Looking at the logs, it see the query execution of FirstDao.getLong, but then my type handler is never reached.
Though, documentation references the typeHandler attribute for the <association> element.
Please note that I am able to use my type handler with a <result> element.
The problem occurs with an <association>.

Thanks for attention
Ludovic

--
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: TypeHandler is not called in association (nested select)

Ludovic Heitz
Hi Iwao, and thanks a lot.
This exactly matches my need!
Thanks for the solution.

Ludovic

Le jeudi 20 avril 2017 17:53:09 UTC+2, Iwao AVE! a écrit :

Hi Ludovic,

Type handler is not used when mapping association.
It is used when building the result of the nested select.

So, you may need to register the type handler in the config.

<typeHandlers>
  <typeHandler
    javaType="MyType" 
    handler="MyTypeHandler"/>
</typeHandlers>

and specify MyType as resultType of the nested query.

<select id="getLong" resultType="MyType">
  select TYPE_COL
  from TYPE_TBL where ...
</select>

The association is pretty simple.

<association
  property="myProperty"
  column="SOME_VALUE"
  select="FirstDao.getLong" />

Regards,
Iwao

2017-04-20 17:20 GMT+09:00 Ludovic Heitz <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="pEOiZLweAgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">ludovic....@...>:
Hello group,

I'm not sure if I found a bug or if I miss something.
I'm working with MyBatis 3.2.8.

I create an implementation of org.apache.ibatis.type.TypeHandler (called MyTypeHandler) to map a Long to a custom type (let's say MyType).

In my first DAO, I got a method like this: Long getLong(Integer).
In a second DAO, I invoke the previous method inside an <association>:

<resultMap...>
    ...
    <association property="myProperty" javaType="MyType" column="SOME_VALUE" select="FirstDao.getLong" typeHandler="MyTypeHandler"/>
</resultMap>

Looking at the logs, it see the query execution of FirstDao.getLong, but then my type handler is never reached.
Though, <a href="http://www.mybatis.org/mybatis-3/sqlmap-xml.html#association" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.mybatis.org%2Fmybatis-3%2Fsqlmap-xml.html%23association\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHVBzMLr7BH6uyHUA1cGv8ig4FBYQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.mybatis.org%2Fmybatis-3%2Fsqlmap-xml.html%23association\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHVBzMLr7BH6uyHUA1cGv8ig4FBYQ&#39;;return true;">documentation references the typeHandler attribute for the <association> element.
Please note that I am able to use my type handler with a <result> element.
The problem occurs with an <association>.

Thanks for attention
Ludovic

--
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="pEOiZLweAgAJ" 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.