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. C遇到的问题

    1. stdout-------printf输出到stdout,并在终端打印 stderr--------perror错误输出到stderr,并在终端打印 2. usleep(1)//代表一微妙 sl ...

  2. 浅谈Service

    一.生命周期: startService()方式启动,Service是通过接受Intent并且会经历onCreate()和onStart().当用户在发出意图使之销毁时会经历onDestroy():( ...

  3. 我的web框架设计

    做了很久的web开发,学了webform和mvc自己总结了,觉得当下的构架还是有改进的可能的. 其实首先说下我的一些认识(个人认知,欢迎讨论,谢绝砸砖). 我觉得对计算机和数据的操作,本身就是一个单向 ...

  4. 带你玩转JavaWeb开发之三 - CSS从基础到实战

    一,什么是CSS? Cascading Style Sheets层叠样式表           层叠:就是层层覆盖叠加,如果有多种样式对同一html标签进行修饰,样式有冲突的部分应用优先级高,不冲突的 ...

  5. windows下的socket网络编程(入门级)

    windows下的socket网络编程 clinet.c 客户端 server.c 服务器端 UDP通信的实现 代码如下 已经很久没有在windows下编程了,这次因为需要做一个跨平台的网络程序,就先 ...

  6. Airline Hub

    参考:http://blog.csdn.net/mobius_strip/article/details/12731459 #include <stdio.h> #include < ...

  7. Difference between Stored Procedure and Function in SQL Server

    Stored Procedures are pre-compile objects which are compiled for first time and its compiled format ...

  8. c#中关键词out和ref的区别

    c#中关键词out和ref用来表明以传引用的方式传递参数. 区别如下: 如果方法的参数用out标记,表示方法被调用前不需初始化参数,方法内不能读取此参数的值,在方法返回前必须向此参数写入值: 如果方法 ...

  9. 将IIS 7,IIS 8运行在32位

    win2008及win2012的IIS运行在32状态下,原因是ASP程序必须在32位下才能使用ACCESS, 只有在32位下,myodbc才会正常,注意,MySQL必须用32位版本. 设置办法: 打开 ...

  10. Swift 懒加载(lazy) 和 Objective-C 懒加载的区别

    在程序设计中,我们经常会使用 懒加载 ,顾名思义,就是用到的时候再开辟空间,比如iOS开发中的最常用控件UITableView,实现数据源方法的时候,通常我们都会这样写 Objective-C - ( ...