Note that there are some explanatory texts on larger screens.

plurals
  1. POusing custom types in MyBatis/Spring
    primarykey
    data
    text
    <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>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload