title: using custom types in MyBatis/Spring
body: <p>I am using MyBatis with Spring Integration as described <a href="http://code.google.com/p/mybatis/wiki/Spring" rel="nofollow">here</a>.</p>
  
  <p>I am further using the Joda Date API instead of the Java Date API, now the tricky bit is ensure that MyBatis recognizes the Joda Date API, and enables me to query the same.</p>
  
  <p>Now the documented way to achieve this is to use a <a href="http://code.google.com/p/mybatis/source/search?q=DateTypeHandler&amp;origq=DateTypeHandler&amp;btnG=Search+Trunk" rel="nofollow">DateTypeHandler</a></p>
  
  <p>I am assuming that if we use the correct annotations, Mybatis will pick up the custom handler and register it with the sqlsessionfactory.</p>
  
  <p>So my class looks like </p>
  
  <pre><code>@MappedTypes(value = DateTime.class)
  @MappedJdbcTypes(value = {JdbcType.DATE,JdbcType.TIME,JdbcType.TIMESTAMP})
  
  public class MyBatisJodaDateTimeType extends DateTypeHandler {
  ......
  .....
  }
  </code></pre>
  
  <p>Some how this does not register my Custom Type handler ...., What I am having to do, is write code like this at application startup ...</p>
  
  <pre><code> 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);
  </code></pre>
  
  <p>I know it looks like crap and i want to avoid it, cant i get MyBatis to scan my application for these annotations and then register my custom type handler automatically ?</p>
  
  <p>I am sure that my type has not been registered (Using just the annotations) because i did a inspect in the MYBatis code and could not find my handler there ....</p>