ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Doug Flex <doug_f...@yahoo.com>
Subject Re: Problem using SelectByExample with TypeHandlerCallback
Date Tue, 05 Aug 2008 18:56:39 GMT
We just started using iBatis, so we don't have a large unit test suite to run yet.  But will
continue to use it and let you know of our vote of confidence.


----- Original Message ----
From: Clinton Begin <clinton.begin@gmail.com>
To: user-java@ibatis.apache.org
Sent: Sunday, August 3, 2008 11:01:51 AM
Subject: Re: Problem using SelectByExample with TypeHandlerCallback

The sooner you deploy 2.3.3 to a staging environment and run your unit test suite, the sooner
it will become official!  :-)

See the two stories on the frontpage, and the blue sidebar on the download page:



On Sun, Aug 3, 2008 at 9:22 AM, Doug Flex <doug_flex@yahoo.com> wrote:

Hi Jeff,

Thanks for your proposed solution.  It looks very promising and it should work, but it doesn't.
 I got the same error.  I also had my co-worker try it on different table with different test
case, it also failed.

The problem was seen using 2.3.0 release.  I downloaded 2.3.3 beta version and the problem
I would be happy to try any other solutions you can think of.  In the mean time, I'll move
foward with 2.3.3 Beta.  Hope that 2.3.3 will be official release very soon.

----- Original Message ----
From: Jeff Butler <jeffgbutler@gmail.com>
To: user-java@ibatis.apache.org
Sent: Thursday, July 31, 2008 6:56:14 PM
Subject: Re: Problem using SelectByExample with TypeHandlerCallback

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:


I have a problem with Null Pointer Exception when trying to use SelectByExample with enum

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
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"/>  

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" 
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

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'
--- 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)

View raw message