在应用mybatis进行一对多嵌套查问时, 报错如下

org.apache.ibatis.exceptions.PersistenceException:
Error querying database. Cause: org.apache.ibatis.executor.ExecutorException: Statement returned more than one row, where no more than one was expected.
The error may exist in com/bigdata/mapper/UserMapper.xml
The error may involve com.bigdata.mapper.UserMapper.findAllOrders
The error occurred while handling results
SQL: select * from orders where uid = ?
Cause: org.apache.ibatis.executor.ExecutorException: Statement returned more than one row, where no more than one was expected.

谬误波及代码如下

谬误大体是说, 箭头指向的sql语句返回的数据行数大于1.
这个在业务上是OK的, 因为orders表是订单表, 一个用户可能有多个订单.
然而在这里后果多行这件事被作为谬误看待, 阐明应该是哪里没有告知mybatis应该应用汇合(或数组)承接后果

最终查找到问题在<collection property="">, property属性值在com.bigdata.domain.User的定义中是Orders, 而不是能够进行遍历的List类型

所以解决形式也很显著了, 将该成员变量改为可迭代类型, 将相应地批改get/set办法以及toString()办法即可