I want to configure a type handler to convert Date columns to LocalDate (Java 8), but I am having trouble registering it. I based my typeHandler on the MyBatis doc and this project.
Mapper:
<resultMap id="clientResult" type="client">
<id property="id" column="id" />
<result property="name" column="name" />
<result property="birthday" column="birthday" />
</resultMap>
Client class:
public class Client {
private Long id;
private String name;
private java.time.LocalDate birthday;
}
The type handler:
@MappedJdbcTypes(value = JdbcType.DATE)
public class LocalDateHandler extends BaseTypeHandler<java.time.LocalDate> {
...
}
I get this error on startup:
org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. Cause: java.lang.IllegalStateException: No typehandler found for property birthday
After some debugging and experimenting, I found multiple solutions.
Solution #1
Remove @MappedJdbcTypes
Solution #2
Change the @MappedJdbcTypes
annotation to use the undocumented includeNullJdbcType = true
@MappedJdbcTypes(value = JdbcType.DATE, includeNullJdbcType = true)
Solution #3
Add a jdbcType
to the resultMap
property:
<result property="birthday" column="birthday" jdbcType="DATE" />
However, I would have expected everything to work as presented above. What's going on? What should I do?
Note: I use MyBatis 3.3.1
update
This is considered a bug for now: https://github.com/mybatis/mybatis-3/issues/591