com.ibatis.common.jdbc.exception.NestedSQLException:Error setting property...
今天一直配Ibatis的时候一直报这个错误,用的是Oracle数据库。
com.ibatis.common.jdbc.exception.NestedSQLException: --- The error occurred in User.xml. --- The error occurred while applying a result map. --- Check the selectAllUser-AutoResultMap. --- The error happened while setting a property on the result object. --- Cause: java.lang.RuntimeException: Error setting property 'setAge' of 'com.ibatis.model.UserInfo@78a212'. Cause: java.lang.IllegalArgumentException 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) at com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.queryForList(SqlMapSessionImpl.java:122) at com.ibatis.sqlmap.engine.impl.SqlMapClientImpl.queryForList(SqlMapClientImpl.java:99) at com.ibatis.dao.UserDao.findAll(UserDao.java:51) at com.ibatis.dao.UserDao.main(UserDao.java:66) Caused by: java.lang.RuntimeException: Error setting property 'setAge' of 'com.ibatis.model.UserInfo@78a212'. Cause: java.lang.IllegalArgumentException at com.ibatis.sqlmap.engine.accessplan.PropertyAccessPlan.setProperties(PropertyAccessPlan.java:52) at com.ibatis.sqlmap.engine.exchange.JavaBeanDataExchange.setData(JavaBeanDataExchange.java:112) at com.ibatis.sqlmap.engine.mapping.result.BasicResultMap.setResultObjectValues(BasicResultMap.java:373) at com.ibatis.sqlmap.engine.mapping.statement.RowHandlerCallback.handleResultObject(RowHandlerCallback.java:64) at com.ibatis.sqlmap.engine.execution.SqlExecutor.handleResults(SqlExecutor.java:382) 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) ... 8 more Caused by: java.lang.IllegalArgumentException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at com.ibatis.sqlmap.engine.accessplan.PropertyAccessPlan.setProperties(PropertyAccessPlan.java:46) ... 16 more Exception in thread "main" java.lang.NullPointerException at com.ibatis.dao.UserDao.main(UserDao.java:66)
找了很多帮助,有说连接池问题的,重启服务后仍不能解决。后来再网上查完后才恍然大悟,原来我的测试数据中int类型的列是null,当查询转换时,不能把null转换成int类型,导致产生异常。
解决方法:
1.填充数据库里的列类型为int的列的数据(有点治标不治本)。
2.加入isnull判断