ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher.Mathru...@sybase.com
Subject Re: SQL Mapping is not working
Date Fri, 16 Jan 2009 19:19:31 GMT
Make certain you register your type handler in you SQL Map Config file, 
similar to as follows:

  <typeHandler javaType="java.util.Calendar" jdbcType="TIMESTAMP" 
callback="your.CalendarTypeHandlerCallback" />

Chris Mathrusse
christopher.mathrusse@sybase.com
Sybase, Inc
One Sybase Drive
Dublin, CA 94568
(925) 236-5553



"Petr V." <greatman787@yahoo.com> 
01/16/2009 11:14 AM
Please respond to
user-java@ibatis.apache.org


To
user-java@ibatis.apache.org
cc

Subject
Re: SQL Mapping is not working







I believe that my type handler is not getting called any time though I am 
registering it. Can some one please have a look at code. I googled it and 
it should work :-(

==============================================================
This is my SQL Map

<sqlMap namespace="MTeacher">
 
    <typeAlias type = "com.Teacher" alias = "Teacher"/> 

    <resultMap id="teacherResult" class="Teacher">
        <result property="id"    column="ID"/> 
        <result property="dob"   column="DOB" 
typeHandler="com.CalendarTypeHandler" jdbcType="TIMESTAMP"/> 
    </resultMap>

 
    <insert id="insertTeacher11">
        INSERT INTO Teacher (id,  dob ) VALUES (#id#, #dob#)
    </insert>

</sqlMap>

========================================================

Exception Log is (It is calling UnknownTypeHandler.setParameter instead of 
my TypeHandler)

------------------------------------------------------------------------------

Caused by: com.ibatis.common.jdbc.exception.NestedSQLException: 
--- The error occurred in maps/Teacher.xml. 
--- The error occurred while applying a parameter map. 
--- Check the insertTeacher11-InlineParameterMap. 
--- Check the parameter mapping for the 'dob' property. 
--- Cause: java.lang.NullPointerException
    at 
com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeUpdate(MappedStatement.java:110)
    at 
com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.update(SqlMapExecutorDelegate.java:457)
    at 
com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.update(SqlMapSessionImpl.java:90)
    at 
org.springframework.orm.ibatis.SqlMapClientTemplate$10.doInSqlMapClient(SqlMapClientTemplate.java:413)
    at 
org.springframework.orm.ibatis.SqlMapClientTemplate.execute(SqlMapClientTemplate.java:209)
    ... 28 more
Caused by: java.lang.NullPointerException
    at 
com.ibatis.sqlmap.engine.type.UnknownTypeHandler.setParameter(UnknownTypeHandler.java:69)
    at 
com.ibatis.sqlmap.engine.mapping.parameter.ParameterMap.setParameter(ParameterMap.java:166)
    at 
com.ibatis.sqlmap.engine.mapping.parameter.ParameterMap.setParameters(ParameterMap.java:126)
    at 
com.ibatis.sqlmap.engine.execution.SqlExecutor.executeUpdate(SqlExecutor.java:78)
    at 
com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.sqlExecuteUpdate(MappedStatement.java:216)
    at 
com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeUpdate(MappedStatement.java:94)
    ... 32 more

Thanks,

Petr

--- On Fri, 1/16/09, Ingmar Lötzsch <iloetzsch@asci-systemhaus.de> wrote:
From: Ingmar Lötzsch <iloetzsch@asci-systemhaus.de>
Subject: Re: SQL Mapping is not working
To: user-java@ibatis.apache.org
Date: Friday, January 16, 2009, 1:58 PM

Petr V. schrieb:
> Any idea what is going on  ? :-( It
 is straight forward code
> 
> ==================================================
> 
> <resultMap class="Job" id="JobResult">
> 
>     <result column="JOB_ID" jdbcType="INTEGER"
property="jobId" />
>     <result column="STATUS" jdbcType="INTEGER"
javaType="JobStatusEnum" 
>              property="jobStatus"
> typeHandler="JobStatusEnumTypeHandlerCallback"/>
> 
> </resultMap>
> 
> ==========================================
> 
> TypeHandler is
> 
> public class JobStatusEnumTypeHandlerCallback implements
> TypeHandlerCallback  {
> 
>     /**
>      *
>      * @param getter
>      * @return
>      * @throws SQLException
>      */
>     public Object getResult(ResultGetter getter) throws SQLException { 
> 
>         Integer intStatus = getter.getInt();
 
>         JobStatusEnum status = null; 
> 
>         if (intStatus != null) { 
>             status = JobStatusEnum.convert(intStatus);
>         } 
> 
>        return status; 
>     } 
> 
>     /**
>      *
>      * @param setter
>      * @param parameter
>      * @throws SQLException
>      */
>     public void setParameter(ParameterSetter setter, Object parameter)
> throws SQLException { 
>         JobStatusEnum status = (JobStatusEnum) parameter; 
>         Integer intStatus = new Integer(status.toIntValue()); 
>         setter.setInt(intStatus); 
>     } 
> 
>     /**
>      *
>      * @param s
>      * @return
>      */
>     public Object valueOf(String s) { 
>         return s; 
>     } 
> 
> ============================================
>
 
> Executing Code
> 
> Job job = new Job();
> job.setId(20);
> job.setStatus(JobStatusEnum.OK);
> 
> ============================================
> 
> Exception Log is
> 
> Caused by: org.firebirdsql.jdbc.field.TypeConvertionException: Error
> converting to int. OK
>     at
>
org.firebirdsql.jdbc.field.FBIntegerField.setString(FBIntegerField.java:124)
>     at
>
org.firebirdsql.jdbc.AbstractPreparedStatement.setString(AbstractPreparedStatement.java:402)
>     at
>
org.apache.commons.dbcp.DelegatingPreparedStatement.setString(DelegatingPreparedStatement.java:132)
>     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>     at
>
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> 
 at
>
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>     at java.lang.reflect.Method.invoke(Method.java:597)
>     at
>
com.ibatis.common.jdbc.logging.PreparedStatementLogProxy.invoke(PreparedStatementLogProxy.java:70)
>     at $Proxy1.setString(Unknown Source)
>     at
>
com.ibatis.sqlmap.engine.type.EnumTypeHandler.setParameter(EnumTypeHandler.java:36)
>     at
>
com.ibatis.sqlmap.engine.mapping.parameter.ParameterMap.setParameter(ParameterMap.java:166)
>     at
>
com.ibatis.sqlmap.engine.mapping.parameter.ParameterMap.setParameters(ParameterMap.java:126)
>     at
>
com.ibatis.sqlmap.engine.execution.SqlExecutor.executeUpdate(SqlExecutor.java:78)
>     at
>
com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.sqlExecuteUpdate(MappedStatement.java:216)
> 
 at
>
com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeUpdate(MappedStatement.java:94)
>     ... 31 more

Have you verified that setParameter() of your type handler is called?
Seems that EnumTypeHandler is used instead.
>
com.ibatis.sqlmap.engine.type.EnumTypeHandler.setParameter(EnumTypeHandler.java:36)


Mime
View raw message