ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Petr V." <greatman...@yahoo.com>
Subject Re: SQL Mapping is not working
Date Fri, 16 Jan 2009 20:03:42 GMT
Please bear with me, this is my first on hand on iBatis, I am coming from hibernate world :-(

Yeah Chris, I did it and I am still getting same exception. It simply does not find my callbackhandler.

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

<sqlMapConfig>

    <typeAlias type = "com.Teacher" alias = "Teacher"/>
    <typeHandler javaType="java.util.Calendar" jdbcType="TIMESTAMP"  callback="com.CalendarTypeHandler"/>
    
    <sqlMap resource="maps/Teacher.xml" />

</sqlMapConfig>

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

Teacher.xml

<sqlMap>

    <resultMap id="teacherResult" class="Teacher">
        <result property="id"    column="ID"/>     
        <result property="name"  column="NAME"/>  
        <result property="dob"   column="DOB"  /> 
    </resultMap>

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

</sqlMap>

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

Java Code that inserts 

Teacher t = new Teacher();
t.setId(135);
t.setName("FromTest");
t.setDob(Calendar.getInstance());
getSqlMapClientTemplate().update("insertTeacher", t);

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

Complete Exception Trace


org.springframework.jdbc.UncategorizedSQLException: SqlMapClient operation; uncategorized
SQLException for SQL []; SQL state [null]; error code [0];   
--- The error occurred in maps/Teacher.xml.  
--- The error occurred while applying a parameter map.  
--- Check the insertTeacher-InlineParameterMap.  
--- Check the parameter mapping for the 'dob' property.  
--- Cause: java.lang.NullPointerException; nested exception is com.ibatis.common.jdbc.exception.NestedSQLException:  

--- The error occurred in maps/Teacher.xml.  
--- The error occurred while applying a parameter map.  
--- Check the insertTeacher-InlineParameterMap.  
--- Check the parameter mapping for the 'dob' property.  
--- Cause: java.lang.NullPointerException
    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:83)
    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
    at org.springframework.orm.ibatis.SqlMapClientTemplate.execute(SqlMapClientTemplate.java:212)
    at org.springframework.orm.ibatis.SqlMapClientTemplate.update(SqlMapClientTemplate.java:411)
    at com.TeacherDaoImpl.insertTeacher(TeacherDaoImpl.java:14)
    at com.SampleManager.insertTeacher(SampleManager.java:28)
    at com.ManagerTest.testInsertTeacher(ManagerTest.java:42)
    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 junit.framework.TestCase.runTest(TestCase.java:168)
    at junit.framework.TestCase.runBare(TestCase.java:134)
    at org.springframework.test.ConditionalTestCase.runBare(ConditionalTestCase.java:69)
    at junit.framework.TestResult$1.protect(TestResult.java:110)
    at junit.framework.TestResult.runProtected(TestResult.java:128)
    at junit.framework.TestResult.run(TestResult.java:113)
    at junit.framework.TestCase.run(TestCase.java:124)
    at junit.framework.TestSuite.runTest(TestSuite.java:232)
    at junit.framework.TestSuite.run(TestSuite.java:227)
    at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:81)
    at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:62)
    at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:140)
    at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:127)
    at org.apache.maven.surefire.Surefire.run(Surefire.java:177)
    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 org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:338)
    at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:997)
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 insertTeacher-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.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 Sat, 1/17/09, Christopher.Mathrusse@sybase.com <Christopher.Mathrusse@sybase.com>
wrote:
From: Christopher.Mathrusse@sybase.com <Christopher.Mathrusse@sybase.com>
Subject: Re: SQL Mapping is not working
To: user-java@ibatis.apache.org
Date: Saturday, January 17, 2009, 12:19 AM



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