JAVA_peakedness
JAVA_peakedness
采纳率40%
2017-08-14 13:52 阅读 1.7k
已采纳

关于mybatis中懒加载的中问题,拜托各位大神了,我检查了好几遍

1

这个是maper配置:







select * from table_many

  <select id="findLazyOne" parameterType="java.lang.String"  resultType="tableOne" >
    select * from table_one t where t.m_id=#{value}
  </select>

        这个是调用方法:
        static TableManyMapper mapper=null;
  public static void main(String[] args) throws Exception {

      String resource="mybatis.xml";
      InputStream input=Resources.getResourceAsStream(resource);    
      SqlSessionFactory factory=new SqlSessionFactoryBuilder().build(input);
      SqlSession sqlSession = factory.openSession();
         mapper=sqlSession.getMapper(TableManyMapper.class);

         findMany();

        sqlSession.commit();
}     
     public static void findMany(){ 
        List<TableMany> list= mapper.findMany();
        for (TableMany tableMany : list) {
            System.out.println(tableMany.getM_id()+"::"+tableMany.getM_name());
            System.out.println(".......");
                List<TableOne> oneList=tableMany.getOneList();
                for (TableOne tableOne : oneList) {
                    System.out.println(tableOne.getO_id()+"::"+tableOne.getO_name());
                }

        }
     }

        这个是报错:
        32acceba-7d07-11e7-acb7-14dda920ec0e::多的一方1

.......
Exception in thread "main" 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:50)
at org.apache.ibatis.executor.loader.ResultLoader.loadResult(ResultLoader.java:71)
at org.apache.ibatis.executor.loader.ResultLoaderMap$LoadPair.load(ResultLoaderMap.java:207)
at org.apache.ibatis.executor.loader.ResultLoaderMap$LoadPair.load(ResultLoaderMap.java:172)
at org.apache.ibatis.executor.loader.ResultLoaderMap.load(ResultLoaderMap.java:80)
at org.apache.ibatis.executor.loader.cglib.CglibProxyFactory$EnhancedResultObjectProxyImpl.intercept(CglibProxyFactory.java:147)
at com.mybatis.pojo.TableMany$$EnhancerByCGLIB$$49d2b6d7.getOneList()
at com.mybatis.test.ManayToOne.findMany(ManayToOne.java:62)
at com.mybatis.test.ManayToOne.main(ManayToOne.java:28)

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

4条回答 默认 最新

  • 已采纳
    qq_33727653 砸死接触 2017-08-15 00:48

    看报错信息是你的方法本来要求查询的语句只能返回一行数据,但是在真正查询的时候出现了两条或更过,所以报错了。看看数据库m_id会不会有重复的?。。。。。。。。是不是楼主代码有部分没贴?

    点赞 评论 复制链接分享
  • Small_Mouse0 鼠小 2017-08-15 05:18
      <select id="findLazyOne" parameterType="java.lang.String"  resultType="tableOne" >
        select * from table_one t where t.m_id=#{value}
      </select>
    

    你居然写*,,,,,很危险,,纠正一下,,开发中尽量不要写 *

    (1)不好看出检索的列(2)*留给数据库解析,,影响效率。

    你的mapper ,resultType="tableOne" ,,没有上传上来,,

    报错:

      Statement returned more than one row, where no more than one was expected.
    声明返回的不止一行,其中不超过预期。
    
    点赞 评论 复制链接分享
  • qq_34445142 爱打架的小白兔 2017-08-15 09:47

    这个问题主要是sql的问题,跑一下sql看下返回的是否是多条数据,或者你本身就是要查询出多条数据,而接受数据的类型不对.基本上逃脱不了这两种情况.

    点赞 评论 复制链接分享
  • JAVA_peakedness JAVA_peakedness 2017-08-15 13:14

    谢谢给位,问题已经解决

    点赞 评论 复制链接分享

相关推荐