Statement returned more than one row, where no more than one was expected

<resultMap id="Student" type="org.mybatis.example.Student">
<id property="id" column="id"/>
<result property="name" column="name"/>
<result property="age" column="age"/>
</resultMap> <resultMap id="InfoResult" type="org.mybatis.example.Student">
<id property="id" column="id" />
<result property="name" column="name" />
<result property="age" column="age" />
<association property="personalInfo" column="id" javaType="org.mybatis.example.PersonalInfo"
select="getPersonalInfo"/>
</resultMap> <select id="getStudentInfo" parameterType="int" resultMap="InfoResult">
select * from student where id &lt; #{id}
</select> <resultMap id="PersonalInfo" type="org.mybatis.example.PersonalInfo">
<id property="id" column="id" />
<result property="height" column="height" />
<result property="weight" column="weight" />
</resultMap> <!-- 选择学生的个人信息 -->
<select id="getPersonalInfo" parameterType="int" resultMap="PersonalInfo">
select * from personal_info where id &lt; #{id}
</select>

下面是测试文件的片段

statement = "org.mybatis.mapping.studentMapper.getStudentInfo";
List<Student> students;
students = session.selectList(statement,2);
System.out.println(students.size());
for(int i=0; i<students.size(); i++) {
System.out.println(students.get(i).toString());

输入2时,返回结果为:

1

Student [name=张三, age=20, id=1, personalInfo=null]

输入3时,返回结果为:

2

Student [name=张三, age=20, id=1, personalInfo=null]

Student [name=李四, age=19, id=2, personalInfo=PersonalInfo [id=1, height=172, weight=67.2]]

输入4时,返回结果为

### 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 org/mybatis/mapping/studentMapper.xml
### The error may involve org.mybatis.mapping.studentMapper.getPersonalInfo
### The error occurred while handling results
### SQL: select * from personal_info where id < ?

我也是服了网上的这群哥哥们,所有的嵌套查询的例子都是输一个id,然后用`id = #{id}`这种条件来查询的,就没有其他的情况么???

Statement returned more than one row, where no more than one was expected的更多相关文章

  1. mybatis中:returned more than one row, where no more than one was expected.异常

    org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.executor.ExecutorEx ...

  2. 精尽MyBatis源码分析 - SQL执行过程(四)之延迟加载

    该系列文档是本人在学习 Mybatis 的源码过程中总结下来的,可能对读者不太友好,请结合我的源码注释(Mybatis源码分析 GitHub 地址.Mybatis-Spring 源码分析 GitHub ...

  3. MyBatis关联查询和懒加载错误

    MyBatis关联查询和懒加载错误 今天在写项目时遇到了个BUG.先说一下背景,前端请求更新生产订单状态,后端从前端接收到生产订单ID进行查询,然后就有问题了. 先看控制台报错: org.apache ...

  4. The command 'new_value' for SQLPlus

    Format: column column_name new_value var_name Meaning: use the column_name of a select statment to c ...

  5. ERROR 1666 (HY000): Cannot execute statement: impossible to write to binary log since statement is in row format and BINLOG_FORMAT = STATEMENT.

    centos7.5 binlog恢复数据失败 问题: mysql> \. /tmp/inc.sql ERROR 1050 (42S01): Table 'new_1' already exist ...

  6. MySQL binlog_format (Mixed,Statement,Row)[转]

    MySQL 5.5 中对于二进制日志 (binlog) 有 3 种不同的格式可选:Mixed,Statement,Row,默认格式是 Statement.总结一下这三种格式日志的优缺点. MySQL ...

  7. 直接放个DB2 SQL STATEMENT大全好了!

    SQL statements   This topic contains tables that list the SQL statements classified by type. SQL sch ...

  8. The Secrets of Oracle Row Chaining and Migration

    from http://www.akadia.com/services/ora_chained_rows.html Overview If you notice poor performance in ...

  9. BINARY SEARCH in read table statement

    1.for standard table, it must be sorted by search key. 2.for sorted table , binary search is used au ...

随机推荐

  1. IOS第二天多线程-05NSOperationQueue 暂停,和恢复队列任务

    *********** #import "HMViewController.h" @interface HMViewController () <UITableViewDel ...

  2. 【转】arcgis server site 快速恢复与重建

    作者:suwenjiang 出处:http://www.cnblogs.com/myyouthlife/ 具体链接:http://www.cnblogs.com/myyouthlife/p/48985 ...

  3. 为 mysql 数据表添加主键

    DROP TABLE IF EXISTS `sdo_actData`.`actCDKey`; CREATE TABLE `sdo_actData`.`actCDKey` ( `RoleID` ) ' ...

  4. ERROR 2006 (HY000) at line xx: MySQL server has gone away 解决方法

  5. 简单理解php的socket编程

    php的socket编程算是比较难以理解的东西吧,不过,我们只要理解socket几个函数之间的关系,以及它们所扮演的角色,那么理解起来应该不是很难了,在笔者看来,socket编程,其实就是建立一个网络 ...

  6. cordova 打包遇到的一些坑

    最近在打包cordova应用的时候遇到不少坑,还是记录下来,免得以后遇到又浪费时间 1.第一个是图片包含中文文字导致的,找了很久,偶然看到一篇文章,有截图如下,忘了哪篇了,不然甩个链接, ,所以下次编 ...

  7. Java中Native关键字的作用

    初次遇见 native是在 java.lang.Object 源码中的一个hashCode方法: 1 public native int hashCode(); 为什么有个native呢?这是我所要学 ...

  8. SQL Server代理警报

    使用SQL Server代理警报的前提条件1.创建操作员,接收消息的用户2.创建警报,满足某种条件触发警报,并作出响应(执行作业或/和通知操作员)3.配置数据库邮件,用于发送消息通知4.SQL Ser ...

  9. url.py中的配置问题

    urlpatterns = [    url(r'^add$', calc_views.add, name='add'),      url(r'^admin/', admin.site.urls), ...

  10. R.java 文件内报错:Underscores can only be used with source level 1.7 or greater。

    R.java 文件内报错:Underscores can only be used with source level 1.7 or greater 网上查找后得知是Android工程图片资源命名的问 ...