[ 
http://issues.apache.org/jira/browse/IBATIS-37?page=comments#action_57349 ]
     
Juergen Hoeller commented on IBATIS-37:
---------------------------------------

Indeed, SqlMapParser still contains the old check: just for a 
TypeHandlerCallback, leading to a ClassCastException with a TypeHandler. For 
example, the following still doesn't work:

<resultMap id="image" class="example.Image">
  <result property="name" column="image_name" 
typeHandler="org.springframework.orm.ibatis.support.ClobStringTypeHandler"/>
</resultMap>

(with ClobStringTypeHandler extending 
com.ibatis.sqlmap.engine.type.BaseTypeHandler).

As a side note, the resulting exception is not too helpful either. Tons of 
nested errors, with nested java.lang.RuntimeExceptions (instead of specific 
exception subclasses) etc.

org.springframework.beans.factory.BeanCreationException: Error creating bean 
with name 'sqlMapClient' defined in file 
[C:\java\spring\spring\work\webroot\WEB-INF\applicationContext.xml]: 
Initialization of bean failed; nested exception is java.lang.RuntimeException: 
Error occurred.  Cause: com.ibatis.common.xml.NodeletException: Error parsing 
XML.  Cause: java.lang.RuntimeException: Error parsing XPath 
'/sqlMapConfig/sqlMap'.  Cause: com.ibatis.common.xml.NodeletException: Error 
parsing XML.  Cause: java.lang.RuntimeException: Error parsing XPath 
'/sqlMap/resultMap/result'.  Cause: java.lang.RuntimeException: Error occurred 
during custom type handler configuration.  Cause: java.lang.ClassCastException
Caused by: java.lang.RuntimeException: Error parsing XPath 
'/sqlMap/resultMap/result'.  Cause: java.lang.RuntimeException: Error occurred 
during custom type handler configuration.  Cause: java.lang.ClassCastException
Caused by: java.lang.RuntimeException: Error parsing XPath 
'/sqlMapConfig/sqlMap'.  Cause: com.ibatis.common.xml.NodeletException: Error 
parsing XML.  Cause: java.lang.RuntimeException: Error parsing XPath 
'/sqlMap/resultMap/result'.  Cause: java.lang.RuntimeException: Error occurred 
during custom type handler configuration.  Cause: java.lang.ClassCastException
Caused by: java.lang.RuntimeException: Error parsing XPath 
'/sqlMap/resultMap/result'.  Cause: java.lang.RuntimeException: Error occurred 
during custom type handler configuration.  Cause: java.lang.ClassCastException
java.lang.RuntimeException: Error occurred.  Cause: 
com.ibatis.common.xml.NodeletException: Error parsing XML.  Cause: 
java.lang.RuntimeException: Error parsing XPath '/sqlMapConfig/sqlMap'.  Cause: 
com.ibatis.common.xml.NodeletException: Error parsing XML.  Cause: 
java.lang.RuntimeException: Error parsing XPath '/sqlMap/resultMap/result'.  
Cause: java.lang.RuntimeException: Error occurred during custom type handler 
configuration.  Cause: java.lang.ClassCastException
Caused by: java.lang.RuntimeException: Error parsing XPath 
'/sqlMap/resultMap/result'.  Cause: java.lang.RuntimeException: Error occurred 
during custom type handler configuration.  Cause: java.lang.ClassCastException
Caused by: java.lang.RuntimeException: Error parsing XPath 
'/sqlMapConfig/sqlMap'.  Cause: com.ibatis.common.xml.NodeletException: Error 
parsing XML.  Cause: java.lang.RuntimeException: Error parsing XPath 
'/sqlMap/resultMap/result'.  Cause: java.lang.RuntimeException: Error occurred 
during custom type handler configuration.  Cause: java.lang.ClassCastException
Caused by: java.lang.RuntimeException: Error parsing XPath 
'/sqlMap/resultMap/result'.  Cause: java.lang.RuntimeException: Error occurred 
during custom type handler configuration.  Cause: java.lang.ClassCastException
        at 
com.ibatis.sqlmap.engine.builder.xml.SqlMapConfigParser.parse(SqlMapConfigParser.java:80)
        at 
com.ibatis.sqlmap.engine.builder.xml.SqlMapConfigParser.parse(SqlMapConfigParser.java:68)
        at 
com.ibatis.sqlmap.client.SqlMapClientBuilder.buildSqlMapClient(SqlMapClientBuilder.java:78)
        at 
org.springframework.orm.ibatis.SqlMapClientFactoryBean.afterPropertiesSet(SqlMapClientFactoryBean.java:214)
        at
...
Caused by: com.ibatis.common.xml.NodeletException: Error parsing XML.  Cause: 
java.lang.RuntimeException: Error parsing XPath '/sqlMapConfig/sqlMap'.  Cause: 
com.ibatis.common.xml.NodeletException: Error parsing XML.  Cause: 
java.lang.RuntimeException: Error parsing XPath '/sqlMap/resultMap/result'.  
Cause: java.lang.RuntimeException: Error occurred during custom type handler 
configuration.  Cause: java.lang.ClassCastException
Caused by: java.lang.RuntimeException: Error parsing XPath 
'/sqlMap/resultMap/result'.  Cause: java.lang.RuntimeException: Error occurred 
during custom type handler configuration.  Cause: java.lang.ClassCastException
Caused by: java.lang.RuntimeException: Error parsing XPath 
'/sqlMapConfig/sqlMap'.  Cause: com.ibatis.common.xml.NodeletException: Error 
parsing XML.  Cause: java.lang.RuntimeException: Error parsing XPath 
'/sqlMap/resultMap/result'.  Cause: java.lang.RuntimeException: Error occurred 
during custom type handler configuration.  Cause: java.lang.ClassCastException
Caused by: java.lang.RuntimeException: Error parsing XPath 
'/sqlMap/resultMap/result'.  Cause: java.lang.RuntimeException: Error occurred 
during custom type handler configuration.  Cause: java.lang.ClassCastException
        at com.ibatis.common.xml.NodeletParser.parse(NodeletParser.java:51)
        at 
com.ibatis.sqlmap.engine.builder.xml.SqlMapConfigParser.parse(SqlMapConfigParser.java:77)
        ... 37 more
Caused by: java.lang.RuntimeException: Error parsing XPath 
'/sqlMapConfig/sqlMap'.  Cause: com.ibatis.common.xml.NodeletException: Error 
parsing XML.  Cause: java.lang.RuntimeException: Error parsing XPath 
'/sqlMap/resultMap/result'.  Cause: java.lang.RuntimeException: Error occurred 
during custom type handler configuration.  Cause: java.lang.ClassCastException
Caused by: java.lang.RuntimeException: Error parsing XPath 
'/sqlMap/resultMap/result'.  Cause: java.lang.RuntimeException: Error occurred 
during custom type handler configuration.  Cause: java.lang.ClassCastException
        at 
com.ibatis.common.xml.NodeletParser.processNodelet(NodeletParser.java:112)
        at com.ibatis.common.xml.NodeletParser.process(NodeletParser.java:73)
        at com.ibatis.common.xml.NodeletParser.process(NodeletParser.java:91)
        at com.ibatis.common.xml.NodeletParser.parse(NodeletParser.java:61)
        at com.ibatis.common.xml.NodeletParser.parse(NodeletParser.java:49)
        ... 38 more
Caused by: com.ibatis.common.xml.NodeletException: Error parsing XML.  Cause: 
java.lang.RuntimeException: Error parsing XPath '/sqlMap/resultMap/result'.  
Cause: java.lang.RuntimeException: Error occurred during custom type handler 
configuration.  Cause: java.lang.ClassCastException
Caused by: java.lang.RuntimeException: Error parsing XPath 
'/sqlMap/resultMap/result'.  Cause: java.lang.RuntimeException: Error occurred 
during custom type handler configuration.  Cause: java.lang.ClassCastException
        at com.ibatis.common.xml.NodeletParser.parse(NodeletParser.java:51)
        at 
com.ibatis.sqlmap.engine.builder.xml.SqlMapParser.parse(SqlMapParser.java:45)
        at 
com.ibatis.sqlmap.engine.builder.xml.SqlMapConfigParser$12.process(SqlMapConfigParser.java:351)
        at 
com.ibatis.common.xml.NodeletParser.processNodelet(NodeletParser.java:110)
        ... 42 more
Caused by: java.lang.RuntimeException: Error parsing XPath 
'/sqlMap/resultMap/result'.  Cause: java.lang.RuntimeException: Error occurred 
during custom type handler configuration.  Cause: java.lang.ClassCastException
        at 
com.ibatis.common.xml.NodeletParser.processNodelet(NodeletParser.java:112)
        at com.ibatis.common.xml.NodeletParser.process(NodeletParser.java:73)
        at com.ibatis.common.xml.NodeletParser.process(NodeletParser.java:91)
        at com.ibatis.common.xml.NodeletParser.process(NodeletParser.java:91)
        at com.ibatis.common.xml.NodeletParser.parse(NodeletParser.java:61)
        at com.ibatis.common.xml.NodeletParser.parse(NodeletParser.java:49)
        ... 45 more
Caused by: java.lang.RuntimeException: Error occurred during custom type 
handler configuration.  Cause: java.lang.ClassCastException
        at 
com.ibatis.sqlmap.engine.builder.xml.SqlMapParser$14.process(SqlMapParser.java:361)
        at 
com.ibatis.common.xml.NodeletParser.processNodelet(NodeletParser.java:110)
        ... 50 more
Caused by: java.lang.ClassCastException
        at 
com.ibatis.sqlmap.engine.builder.xml.SqlMapParser$14.process(SqlMapParser.java:358)
        ... 51 more
Exception in thread "main" Process terminated with exit code 1

Juergen

> Allow typeHandler class to implement TypeHandler interface
> ----------------------------------------------------------
>
>          Key: IBATIS-37
>          URL: http://issues.apache.org/jira/browse/IBATIS-37
>      Project: iBatis for Java
>         Type: Improvement
>   Components: SQL Maps
>     Versions: 2.0.8
>     Reporter: Juergen Hoeller
>     Assignee: Clinton Begin
>      Fix For: 2.0.9

>
> Hi Clinton and team,
> We plan to provide BLOB/CLOB type handlers for iBATIS SQL Maps 2 in Spring, 
> delegating to Spring's LobHandler abstraction. I've checked out your new 
> TypeHandler support, which looks like a nice hook for this.
> Spring's LobHandler expects to work on PreparedStatements and ResultSets. For 
> this reason, the TypeHandlerCallback mechanism in SQL Maps cannot be used; we 
> need to provide plain TypeHandler implementations. I've already implemented 
> such TypeHandlers; there's no obstacle there.
> Unfortunately, the typeHandler attribute in XML SQL mapping files just 
> accepts TypeHandlerCallback implementations as of iBATIS 2.0.8, throwing a 
> nasty ClassCastException else.
> To make this more flexible, I suggest to load the specified class and check 
> whether it is a TypeHandler or TypeHandlerCallback implementation. This 
> should be straightforward to add to XmlSqlMapClientBuilder: just add a 
> corresponding check to line 912/913.
>   Object typeHandler = Resources.classForName(callback).newInstance();
>   if (typeHandler instanceof TypeHandler) {
>     handler = (TypeHandler) handler;
>   }
>   else if (typeHandler instanceof TypeHandlerCallback) {
>     handler = new CustomTypeHandler((TypeHandlerCallback) 
> typeHandlerCallback);
>   }
>   else {
>     throw SqlMapException("Invalid type handler class: ...");
>   }
> This should be pretty trivial to add and not cause any side effects, as far 
> as I can see. It would be great if you could get this into iBATIS 2.0.9 (or 
> whatever your next planned release is).
> Thanks in advance,
> Juergen

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
If you want more information on JIRA, or have a bug to report see:
   http://www.atlassian.com/software/jira

Reply via email to