ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jeff Butler" <jeffgbut...@gmail.com>
Subject Re: iBatis Typehandler problem
Date Fri, 19 Jan 2007 15:41:01 GMT
Register your type handler without the jdbcType property like this:

<typeHandler javaType="org.joda.time.DateTime"
       callback="org.yusuf.utils.typehandlers.DateTimeTypeHandler" />

I think that will work.  iBATIS will not use the jdbcType unless it is
specified in an in-line parameter map.

Jeff Butler


On 1/19/07, Yusuf <Yusuf@ekalife.co.id> wrote:
>
> Hi all, i browsed through
> http://opensource.atlassian.com/confluence/oss/display/IBATIS/How+do+I+u
> se+a+Custom+Type+Handler+with+complex+property+or+Type+Safe+Enumeration
> but still can't seem to solve this problem...
>
> I have this setup in the config (i'm trying to use joda's DateTime to
> override java.util.Date typehandler) :
>
> <typeHandler javaType="org.joda.time.DateTime" jdbcType="DATE"
>        callback="org.yusuf.utils.typehandlers.DateTimeTypeHandler" />
>
> the typehandler :
>
> public class DateTimeTypeHandler implements TypeHandlerCallback {
>
>        public Object getResult(ResultGetter getter) throws SQLException
> {
>                Timestamp ts = getter.getTimestamp();
>                System.out.println(getter.toString());
>                return new DateTime(ts);
>        }
>
>        public void setParameter(ParameterSetter setter, Object
> parameter) throws SQLException {
>                DateTime dt = (DateTime) parameter;
>                setter.setTimestamp(new Timestamp(dt.getMillis()));
>        }
>
>        public Object valueOf(String s) {
>                return s;
>        }
> }
>
> the database (HSQL) :
>
> create table mst_birthday(
>        id NUMERIC,
>        userName VARCHAR,
>        birthDay DATE);
>
> the query :
>
> <select id="selectBirthday" resultClass="command">
>        select id int1, userName string1, birthDay date1 from
> mst_birthday
> </select>
>
> and the resultclass :
>
> public class Command implements Serializable {
>
>        private Integer int1;
>        private String string1;
>        private DateTime date1;
>        private DateTime date2;
>
>        //getter setter
> }
>
> but everytime i tried to run the query, this exception occured, can
> someone help me? thanks in advance :
>
> Exception :
> org.springframework.jdbc.UncategorizedSQLException: SqlMapClient
> operation; uncategorized SQLException for SQL []; SQL state [null];
> error code [0];
> --- The error occurred in org/yusuf/demo/dao/sql/db.xml.
> --- The error occurred while applying a result map.
> --- Check the org.yusuf.db.selectBirthday-AutoResultMap.
> --- Check the result mapping for the 'date1' property.
> --- Cause: com.ibatis.sqlmap.client.SqlMapException: No type handler
> could be found to map the property 'date1' to the column 'DATE1'.  One
> or both of the types, or the combination of types is not supported.;
> nested exception is com.ibatis.common.jdbc.exception.NestedSQLException:
>
> --- The error occurred in org/yusuf/demo/dao/sql/db.xml.
> --- The error occurred while applying a result map.
> --- Check the org.yusuf.db.selectBirthday-AutoResultMap.
> --- Check the result mapping for the 'date1' property.
> --- Cause: com.ibatis.sqlmap.client.SqlMapException: No type handler
> could be found to map the property 'date1' to the column 'DATE1'.  One
> or both of the types, or the combination of types is not supported.
>    at
> org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.translat
> e(SQLStateSQLExceptionTranslator.java:97)
>    at
> org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.tran
> slate(SQLErrorCodeSQLExceptionTranslator.java:268)
>    at
> org.springframework.orm.ibatis.SqlMapClientTemplate.execute(SqlMapClient
> Template.java:168)
>    at
> org.springframework.orm.ibatis.SqlMapClientTemplate.executeWithListResul
> t(SqlMapClientTemplate.java:187)
>    at
> org.springframework.orm.ibatis.SqlMapClientTemplate.queryForList(SqlMapC
> lientTemplate.java:226)
>    at org.yusuf.utils.parents.ParentDao.query(ParentDao.java:58)
>    at org.yusuf.demo.dao.DbDao.selectBirthday(DbDao.java:46)
>    at
> org.yusuf.demo.service.DbManager.selectBirthday(DbManager.java:50)
>    at
> org.yusuf.demo.service.DbManager$$FastClassByCGLIB$$3a1e77bb.invoke(<gen
> erated>)
>    at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)
>    at
> org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.i
> nvokeJoinpoint(Cglib2AopProxy.java:709)
>    at
> org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(Ref
> lectiveMethodInvocation.java:148)
>    at
> org.springframework.transaction.interceptor.TransactionInterceptor.invok
> e(TransactionInterceptor.java:100)
>    at
> org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(Ref
> lectiveMethodInvocation.java:170)
>    at
> org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedIntercept
> or.intercept(Cglib2AopProxy.java:647)
>    at
> org.yusuf.demo.service.DbManager$$EnhancerByCGLIB$$c059554a.selectBirthd
> ay(<generated>)
>    at
> org.yusuf.demo.web.TypeHandlerController.handleRequest(TypeHandlerContro
> ller.java:24)
>    at
> org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handl
> e(SimpleControllerHandlerAdapter.java:45)
>    at
> org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherS
> ervlet.java:797)
>    at
> org.springframework.web.servlet.DispatcherServlet.doService(DispatcherSe
> rvlet.java:727)
>    at
> org.springframework.web.servlet.FrameworkServlet.processRequest(Framewor
> kServlet.java:396)
>    at
> org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.
> java:350)
>    at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
>    at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
>    at
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Applica
> tionFilterChain.java:252)
>    at
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilt
> erChain.java:173)
>    at
> com.opensymphony.module.sitemesh.filter.PageFilter.parsePage(PageFilter.
> java:119)
>    at
> com.opensymphony.module.sitemesh.filter.PageFilter.doFilter(PageFilter.j
> ava:55)
>    at
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Applica
> tionFilterChain.java:202)
>    at
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilt
> erChain.java:173)
>    at
> org.displaytag.filter.ResponseOverrideFilter.doFilter(ResponseOverrideFi
> lter.java:125)
>    at
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Applica
> tionFilterChain.java:202)
>    at
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilt
> erChain.java:173)
>    at
> org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValv
> e.java:213)
>    at
> org.apache.catalina.core.StandardContextValve.invoke(StandardContextValv
> e.java:178)
>    at
> org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java
> :126)
>    at
> org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java
> :105)
>    at
> org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.
> java:107)
>    at
> org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:1
> 48)
>    at
> org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.j
> ava:833)
>    at
> org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.proce
> ss(Http11AprProtocol.java:639)
>    at
> org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1285)
>    at java.lang.Thread.run(Thread.java:595)
>
> Regards,
> Yusuf
>
>

Mime
View raw message