1

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

bernie
  • 9,820
  • 5
  • 62
  • 92
  • Possible duplicate of [Java 8 LocalDate mapping with mybatis](http://stackoverflow.com/questions/25113579/java-8-localdate-mapping-with-mybatis) – haihui Feb 26 '16 at 04:28
  • I actually used that question as a reference for my implementation but something is not working with `@MappedJdbcTypes` – bernie Feb 26 '16 at 16:17

0 Answers0