ClassCastException when mapping primitive arrays due to attempts to cast to
object arrays made by iBatis
--------------------------------------------------------------------------------------------------------
Key: IBATIS-456
URL: https://issues.apache.org/jira/browse/IBATIS-456
Project: iBatis for Java
Issue Type: Bug
Components: SQL Maps
Affects Versions: 2.3.0
Reporter: Jonathan Alvarsson
Priority: Blocker
When mapping an array of primitives (at least doubles) iBatis when injecting
the array seems to try to cast it to an array of objects which results in
something like this:
org.springframework.jdbc.UncategorizedSQLException: SqlMapClient operation;
uncategorized SQLException for SQL []; SQL state [null]; error code [0];
--- The error occurred in mapping/MoleculeDescriptor.xml.
--- The error occurred while applying a result map.
--- Check the MoleculeDescriptor.
--- Check the result mapping for the 'values' property.
--- Cause: java.lang.ClassCastException: [D; nested exception is
com.ibatis.common.jdbc.exception.NestedSQLException:
--- The error occurred in mapping/MoleculeDescriptor.xml.
--- The error occurred while applying a result map.
--- Check the MoleculeDescriptor.
--- Check the result mapping for the 'values' property.
--- Cause: java.lang.ClassCastException: [D
Caused by: com.ibatis.common.jdbc.exception.NestedSQLException:
--- The error occurred in mapping/MoleculeDescriptor.xml.
--- The error occurred while applying a result map.
--- Check the MoleculeDescriptor.
--- Check the result mapping for the 'values' property.
--- Cause: java.lang.ClassCastException: [D
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:615)
at
com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList(SqlMapExecutorDelegate.java:589)
at
com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.queryForList(SqlMapSessionImpl.java:118)
[snipp....]
Caused by: java.lang.ClassCastException: [D
at
com.ibatis.sqlmap.engine.mapping.result.loader.ResultLoader.listToArray(ResultLoader.java:85)
at
com.ibatis.sqlmap.engine.mapping.result.loader.ResultLoader.getResult(ResultLoader.java:75)
at
com.ibatis.sqlmap.engine.mapping.result.loader.ResultLoader.loadResult(ResultLoader.java:59)
at
com.ibatis.sqlmap.engine.mapping.result.BasicResultMap.getNestedSelectMappingValue(BasicResultMap.java:502)
at
com.ibatis.sqlmap.engine.mapping.result.BasicResultMap.getResults(BasicResultMap.java:340)
at
com.ibatis.sqlmap.engine.execution.SqlExecutor.handleResults(SqlExecutor.java:381)
at
com.ibatis.sqlmap.engine.execution.SqlExecutor.handleMultipleResults(SqlExecutor.java:301)
at
com.ibatis.sqlmap.engine.execution.SqlExecutor.executeQuery(SqlExecutor.java:190)
at
com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.sqlExecuteQuery(GeneralStatement.java:205)
at
com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryWithCallback(GeneralStatement.java:173)
... 46 more
Following fix suggested by [EMAIL PROTECTED]:
ResultLoader.java:
private static Object listToArray(List list, Class type) {
Object array = java.lang.reflect.Array.newInstance(type, list.size());
if (type.isPrimitive()) {
Iterator iter = list.iterator();
int index = 0;
while (iter.hasNext()) {
Array.set(array, index++, iter.next());
}
} else {
array = list.toArray((Object[]) array);
}
return array;
}
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.