<resultMap id="special_boolean" type="boolean">
<constructor>
<arg column="your_column" typeHandler="YourTypeHandler"/>
</constructor>
</resultMap>
Christian
-----Message d'origine-----
De : mybati...@googlegroups.com [mailto:mybati...@googlegroups.com] De la part de Truth
Envoyé : February-21-11 5:22 PM
À : mybatis-user
Objet : Type Handler for Single Primitive Result Type
The suggested solution didn't work for us, we always got a false
response regardless of input.
Throwing some debug tracing on, it seems with the resultMap type of
Boolean the typehandler we specify never gets called.
<resultMap id="special_boolean" type="Boolean">
<constructor>
<arg column="our_column" javaType="_boolean" typeHandler="OurTypeHandler"/>
</constructor>
</resultMap>
However on our own customer class, the typehandler still gets called:
<resultMap id="special_boolean" type="BooleanContainer">
<constructor>
<arg column="our_column" javaType="_boolean" typeHandler="OurTypeHandler"/>
</constructor>
</resultMap>
Is there some sort for automatic handler for a resultMap type of
Boolean that we cannot override?
--
Truth.
On 23 February 2011 02:39, Poitras Christian
You can try either
SqlSessionFactory.getConfiguration().getTypeHandlerRegistry().register(Boolean.TYPE, YourTypeHandler);
Or register a JdbcType that match your data like
sqlSessionFactory.getConfiguration().getTypeHandlerRegistry().register(JdbcType.BIT, YourTypeHandler);
I haven't tried that for boolean.
You may also prefer to have a private special getter/setter/constructor that doesn't use boolean but another type that is easier to deal with.
Christian
-----Message d'origine-----
De : mybati...@googlegroups.com [mailto:mybati...@googlegroups.com] De la part de Truth
Envoyé : March-27-11 7:05 PM
À : mybati...@googlegroups.com
Objet : Re: Type Handler for Single Primitive Result Type
Theoretically your previous suggestion should work, however when
MyBatis sees the resultMap type of Boolean, it doesn't process the
rest of the resultMap. It would appear the default handler for Boolean
overrides any custom resultMap specified for it.
The alternative I would have hoped for was the ability to set a
typeHandler for the result of a select where a resultType has been
specified.
At the moment for a work around, we've created our own
BooleanContainer custom type which we handling as per a normal
JavaBean - and inserting a dummy DAO layer between the actual DAO and
the Service call - that unwraps this BooleanContainer and returns a
boolean to match the API spec. However it seems a hack to hack to do
so, and the additional (minimal) overhead of another Bean being
managed.
Unless I've missed something it seems the default overriding the
resultMap for Boolean is a bug. And the lack of ability to specify a
typeHandler for a single result from a select statement a missing gap
in our functionality.
--
Truth.
It's somewhat annoying, but I was expecting that MyBatis would have a
simple solution. Or at least simpler than our current work-around.
--
Truth.
--
Truth.
But I still think there should be a way of doing this, as is.
--
Truth.
If you can set the Boolean as a <result> of another class, it would be very easy.
<resultMap id="someMap" type="SomeClass">
<result property="my_boolean" column="our_column" typeHandler="OurTypeHandler"/>
</resultMap>
Christian
-----Message d'origine-----
De : mybati...@googlegroups.com [mailto:mybati...@googlegroups.com] De la part de Truth
Envoyé : March-28-11 4:59 PM
Maybe there is. I’ve never done this myself, so I’m not sure.
As for your suggestion to modify the select output, this is what I use to convert values like ‘N’ and ‘Y’ to boolean.
Christian
De : mybati...@googlegroups.com [mailto:mybati...@googlegroups.com] De la part de lwpro
Envoyé : March-29-11 9:32 AM