MyBatis Parameter not found

遇到一个很牛X的问题。当MyBatis的foreach中item='cr'时,程序居然抛出异常:
19:07:55.338 DEBUG c.l.dao.PageMapper.selectByCriteria - ==>  Preparing: select id, pag_id, title, content, status, create_date, modified_date from page WHERE ( pag_id = ? and status = ? ) order by modified_date desc 
19:07:55.378 DEBUG org.mybatis.spring.SqlSessionUtils - Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@3f68f2a4]
19:07:55.379 DEBUG o.s.jdbc.datasource.DataSourceUtils - Returning JDBC Connection to DataSource
19:07:55.382 DEBUG o.a.struts2.dispatcher.Dispatcher - Exception occurred during processing request: nested exception is org.apache.ibatis.binding.BindingException: Parameter '__frch___frch_cr_0iterion_1' not found. Available parameters are [col, param1, page, param2, param3, wcriteria]
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter '__frch___frch_cr_0iterion_1' not found. Available parameters are [col, param1, page, param2, param3, wcriteria]
    ……
Caused by: org.apache.ibatis.binding.BindingException: Parameter '__frch___frch_cr_0iterion_1' not found. Available parameters are [col, param1, page, param2, param3, wcriteria]
    ……
当把cr改成c后,程序依然异常:
19:11:35.496 DEBUG c.l.dao.PageMapper.selectByCriteria - ==>  Preparing: select id, pag_id, title, content, status, create_date, modified_date from page WHERE ( pag_id = ? and status = ? ) order by modified_date desc 
19:11:35.531 DEBUG org.mybatis.spring.SqlSessionUtils - Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@270b6d1c]
19:11:35.532 DEBUG o.s.jdbc.datasource.DataSourceUtils - Returning JDBC Connection to DataSource
19:11:35.534 DEBUG o.a.struts2.dispatcher.Dispatcher - Exception occurred during processing request: nested exception is org.apache.ibatis.binding.BindingException: Parameter '__fr__frch_c_0h_criterion_1' not found. Available parameters are [col, param1, page, param2, param3, wcriteria]
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter '__fr__frch_c_0h_criterion_1' not found. Available parameters are [col, param1, page, param2, param3, wcriteria]
……
Caused by: org.apache.ibatis.binding.BindingException: Parameter '__fr__frch_c_0h_criterion_1' not found. Available parameters are [col, param1, page, param2, param3, wcriteria]
    
当改成cri后,异常依旧在:
19:13:33.702 DEBUG c.l.dao.PageMapper.selectByCriteria - ==>  Preparing: select id, pag_id, title, content, status, create_date, modified_date from page WHERE ( pag_id = ? and status = ? ) order by modified_date desc 
19:13:33.740 DEBUG org.mybatis.spring.SqlSessionUtils - Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@76d56dba]
19:13:33.740 DEBUG o.s.jdbc.datasource.DataSourceUtils - Returning JDBC Connection to DataSource
19:13:33.742 DEBUG o.a.struts2.dispatcher.Dispatcher - Exception occurred during processing request: nested exception is org.apache.ibatis.binding.BindingException: Parameter '__frch___frch_cri_0terion_1' not found. Available parameters are [col, param1, page, param2, param3, wcriteria]
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter '__frch___frch_cri_0terion_1' not found. Available parameters are [col, param1, page, param2, param3, wcriteria]
……
Caused by: org.apache.ibatis.binding.BindingException: Parameter '__frch___frch_cri_0terion_1' not found. Available parameters are [col, param1, page, param2, param3, wcriteria]

当改成criteria后,程序就正常了,起初我还以为是item对长度有限值,可是没听说啊。于是决定把cr改成ab试一下,奇迹不总是发生在长度上,居然没有异常。不晓得MyBatis是不是在哪个不起眼的地方对这个问题有说明,也或许他是一个bug,不管是哪种情况,如果你也遇到了,希望对你有帮助。

posted @ 2013-06-28 19:35  MagicLetters  阅读(2863)  评论(0编辑  收藏  举报