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: Problem using SelectByExample with TypeHandlerCallback
Date Fri, 01 Aug 2008 00:56:14 GMT
Try this column override in your (i)abatorConfig:

        <columnOverride column="LOCATION_TYPE" javaType="LocationType"
         typeHandler="LocationTypeTypeHandler" />
This will cause (i)abator to generate code that explicitly calls the type
handler.  I'm fairly certain this will solve the problem.  Without this,
then we're possibly dealing with a limitation in iBATIS.  The ByExample
dynamic SQL is very complex and I don't think iBATIS is able to do as much
runtime introspection to resolve the type handler as is needed here.

Jeff Butler

On Thu, Jul 31, 2008 at 11:10 AM, Doug Flex <doug_flex@yahoo.com> wrote:

>  Hi,
>
> I have a problem with Null Pointer Exception when trying to use
> SelectByExample with enum criteria.
>
> I have done the following to seek for answer but have no success yet.
> Please help!
>
> - google
> - looked through iBatis FAQ
> - looked through iBatis WIKI
> - looked thought iBatis mailing archive
>
> the code described below omits full package path for readability
> ------------------
> 1) I specified type conversion for a column in AbatorConfig.xml.  This
> generated code with the
> VARCHAR mapped to Java enum LocationType correctly.  The generated code was
> Java 5, Spring Dao style.
>     <table tableName="LOCATION">
>         <columnOverride column="LOCATION_TYPE" javaType="LocationType"/>
>      </table>
>
> 2) I have a class that called LocationTypeTypeHandler which implement
> TypeHandlerCallback to map database VARCHAR to Java enum LocationType
>
> 3)  I specified the usage of the callback in SQLMapConfig.xml as follows:
> <typeHandler javaType="LocationType"
>                   jdbcType="VARCHAR"
>                   callback="LocationTypeTypeHandler"/>
> 4) Most of the cases such as SelectByPrimimaryKey, insert, etc...seems to
> be working.  So, I know that my enum type conversion using
> LocationTypeTypeHandler was configured and invoked correctly.  The problem I
> ran into was when using SelectByExample with line d) below.  If I commented
> out line d) then the query works ok.
>
>        a) LocationExample example = new LocationExample();
>        b) LocationExample.Criteria criteria = example.createCriteria();
>        c) criteria.andLocationIdEqualTo(1);
>        d) criteria.andLocationTypeEqualTo(LocationType.GENERAL);
>        e) List<Location> result = locationDao.selectByExample(example);
>
> 5) The stack trace are shown below.  Using the debugger, all the data looks
> to be valid, especially 'oredCriteria[0].criteriaWithSingleValue[1].value'
>
> Caused by: com.ibatis.common.jdbc.exception.NestedSQLException:
> --- The error occurred while applying a parameter map.
> --- Check the LOCATION.abatorgenerated_selectByExample-InlineParameterMap.
>
> --- Check the parameter mapping for the
> 'oredCriteria[0].criteriaWithSingleValue[1].value' property.
> --- Cause: java.lang.NullPointerException
> Caused by: java.lang.NullPointerException
>     at
> com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryWithCallback(GeneralStatement.java:188)
>     at
> com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryForList(GeneralStatement.java:123)
>     at
> com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList(SqlMapExecutorDelegate.java:614)
>     at
> com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList(SqlMapExecutorDelegate.java:588)
>     at
> com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.queryForList(SqlMapSessionImpl.java:118)
>     at
> org.springframework.orm.ibatis.SqlMapClientTemplate$3.doInSqlMapClient(SqlMapClientTemplate.java:298)
>     at
> org.springframework.orm.ibatis.SqlMapClientTemplate.execute(SqlMapClientTemplate.java:209)
>     ... 23 more
> Caused by: java.lang.NullPointerException
>     at
> com.ibatis.sqlmap.engine.type.UnknownTypeHandler.setParameter(UnknownTypeHandler.java:70)
>     at
> com.ibatis.sqlmap.engine.mapping.parameter.BasicParameterMap.setParameter(BasicParameterMap.java:165)
>     at
> com.ibatis.sqlmap.engine.mapping.parameter.BasicParameterMap.setParameters(BasicParameterMap.java:125)
>     at
> com.ibatis.sqlmap.engine.execution.SqlExecutor.executeQuery(SqlExecutor.java:180)
>     at
> com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.sqlExecuteQuery(GeneralStatement.java:205)
>     at
> com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryWithCallback(GeneralStatement.java:173)
>
>
>

Mime
View raw message