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)