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

org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.executor.ExecutorException: Statement returned more than one row, where no more than one was expected.
    at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:75) ~[MyBatisExceptionTranslator.class:1.2.2]
    at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:371) ~[SqlSessionTemplate$SqlSessionInterceptor.class:1.2.2]
Caused by: org.apache.ibatis.executor.ExecutorException: Statement returned more than one row, where no more than one was expected.
    at org.apache.ibatis.executor.ResultExtractor.extractObjectFromList(ResultExtractor.java:58) ~[ResultExtractor.class:3.2.8]
    at org.apache.ibatis.executor.loader.ResultLoader.loadResult(ResultLoader.java:71) ~[ResultLoader.class:3.2.8]
由于查找出了多个对象,一般查找的那个字段是数据有重复。
程序期望返回不超过一行数据,但实际返回了多于一行的数据。

比如sql语句的返回类型是非集合类型,但返回了多行数据。
时间: 2024-08-10 00:42:59

mybatis中:returned more than one row, where no more than one was expected.异常的相关文章

mybatis中many2one

上一章我们讲到,如果说hibernate是面向对象为主,关系为辅,那么在mybatis中则是着重考虑的是关系模型,换句话说,如果对象模型设计的不好,就会很容易的感觉到实现的难度. 首先来看看最简单的单向many2one: 建立对象: public class Customer {     private Long id;     private String name; } public class Orders {     private Long id;     private String

2017年9月3日 Spring及Mybatis中连接数据库的不同方式

连接数据库用spring和mybatis中使用的方法可以不同,mybaits可以不用写数据库的配置文件 Spring的连接方法 <!-- 读取属性文件(.properties)的内容 --> <!-- location:指定要读取的属性文件的位置及文件名. 注: classpath:表示依据类路径去查找 容器依据路径读取属性文件的内容, 并且将这些内容存放到Properties对象上 --> //数据库的登入数据文件 //文件名db.properties #db connectio

mybatis中&quot;#&quot;和&quot;$&quot;的区别

mybatis中"#"和"$"的区别 动态 sql 是 mybatis 的主要特性之一,在 mapper 中定义的参数传到 xml 中之后,在查询之前 mybatis 会对其进行动态解析.mybatis 为我们提供了两种支持动态 sql 的语法:#{} 以及 ${}. 在下面的语句中,如果 username 的值为 zhangsan,则两种方式无任何区别: select * from user where name = #{name}; select * from

mybatis中的mapper接口文件以及example类的实例函数以及详解

##Example example = new ##Example(); example.setOrderByClause("字段名 ASC"); //升序排列,desc为降序排列. example.setDistinct(false)//去除重复,boolean型,true为选择不重复的记录. Criteria criteria = new Example().createCriteria(); is null;is not null; equal to(value);not equ

MyBatis中如何通过继承SqlSessionDaoSupport来编写DAO(一)

在MyBatis中,当我们编写好访问数据库的映射器接口后,MapperScannerConfigurer就能自动成批地帮助我们根据这些接口生成DAO对象(),然后我们再使用Spring把这些DAO对象注入到业务逻辑层的对象(Service类的对象).因此,在这种情况下的DAO层,我们几乎不用编写代码,而且也没有地方编写,因为只有接口.这固然方便,不过如果我们需要在DAO层写一些代码的话,这种方式就无能为力了.此时,MyBatis-Spring提供给我们的SqlSessionDaoSupport类

MyBatis中的OGNL教程

MyBatis中的OGNL教程 有些人可能不知道MyBatis中使用了OGNL,有些人知道用到了OGNL却不知道在MyBatis中如何使用,本文就是讲如何在MyBatis中使用OGNL. 如果我们搜索OGNL相关的内容,通常的结果都是和Struts有关的,你肯定搜不到和MyBatis有关的,虽然和Struts中的用法类似但是换种方式理解起来就有难度. MyBatis常用OGNL表达式 e1 or e2 e1 and e2 e1 == e2,e1 eq e2 e1 != e2,e1 neq e2

myBatis中的注解@Param、返回值为Map、JAVA读取Excel并解析文本、Class.getResource()和ClassLoader.getResource()

myBatis中的注解@Param:http://blog.csdn.net/gao36951/article/details/44258217:  http://www.cnblogs.com/thomas12112406/p/6217211.html. myBatis返回值为Map:http://blog.csdn.net/werewr342352321df/article/details/11892755. ====================== JAVA读取Excel并解析文本:h

mybatis中xml的sql之test中文报错

在mybatis中sql,test中文报错( java.lang.NumberFormatException 这句话明确告诉了我们是数字格式异常).需加.tostring(). <if test="bookName == '毛选集'.tostring() "> and b.book_Name like #{bookName} </if>

Mybatis中的resultType和resultMap 区别

Mybatis中的resultType和resultMap 是mybatis 中返回类型一定用到的,但不会同时出现.mybatis返回类型肯定是map结构,然后根据返回类型是map还是对象类型,再转换. 在给对象设置属性的时候,两个方法肯定会调用. private Object getRowValue(ResultSetWrapper rsw, ResultMap resultMap) throws SQLException { final ResultLoaderMap lazyLoader