I am using MyBatis with Spring Integration as described here .
I use the Joda Date API instead of the Java Date API, now the complex bit ensures that MyBatis recognizes the Joda Date API and allows me to request the same.
Now the documented way to achieve this is to use DateTypeHandler
I assume that if we use the correct annotations, Mybatis will take a custom handler and register it using sqlsessionfactory.
So my class looks like
@MappedTypes(value = DateTime.class) @MappedJdbcTypes(value = {JdbcType.DATE,JdbcType.TIME,JdbcType.TIMESTAMP}) public class MyBatisJodaDateTimeType extends DateTypeHandler { ...... ..... }
Some, as my custom type handler does not register this .... I need to make such code as when I started the application ...
SqlSessionFactory mybatisSessionFactory = applicationContext.getBean("sqlSessionFactory", SqlSessionFactory.class); MyBatisJodaDateTimeType myBatisJodaDateTimeType = applicationContext.getBean("myBatisJodaDateTimeType", MyBatisJodaDateTimeType.class); mybatisSessionFactory.getConfiguration().getTypeHandlerRegistry().register(DateTime.class, myBatisJodaDateTimeType); mybatisSessionFactory.getConfiguration().getTypeHandlerRegistry().register(DateTime.class, JdbcType.DATE, myBatisJodaDateTimeType); mybatisSessionFactory.getConfiguration().getTypeHandlerRegistry().register(DateTime.class, JdbcType.TIME, myBatisJodaDateTimeType); mybatisSessionFactory.getConfiguration().getTypeHandlerRegistry().register(DateTime.class, JdbcType.TIMESTAMP, myBatisJodaDateTimeType); mybatisSessionFactory.getConfiguration().getTypeHandlerRegistry().register(DateTime.class, null, myBatisJodaDateTimeType);
I know this looks like shit, and I want to avoid this, can MyBatis scan my application for these annotations and then automatically register a custom type handler?
I am sure that my type was not registered (using only annotations) because I checked in MYBatis code and could not find my handler there.