Query query = getSession().createQuery("from StudentApplyPO");   
     query.setFirstResult(0);
     query.setMaxResults(2);
     query.list();这个不报错当我把query.setFirstResult(1);设置为0以上的数字就要报错
而其报错生成的SQL语句可以再查询分析器里面执行成功这个是怎么会是大哥些帮帮忙啊··

解决方案 »

  1.   

    log4j:WARN No appenders could be found for logger (org.springframework.core.CollectionFactory).
    log4j:WARN Please initialize the log4j system properly.
    Hibernate: select top 3 studentapp0_.t_sigid as t1_, studentapp0_.t_name as t2_1_, studentapp0_.t_sex as t3_1_, studentapp0_.t_brithday as t4_1_, studentapp0_.t_nation as t5_1_, studentapp0_.t_native as t6_1_, studentapp0_.t_idCrad as t7_1_, studentapp0_.t_address as t8_1_, studentapp0_.t_polity as t9_1_, studentapp0_.t_phone as t10_1_, studentapp0_.t_familyphone as t11_1_, studentapp0_.t_highschool as t12_1_, studentapp0_.t_schoolAge as t13_1_, studentapp0_.t_studyType as t14_1_, studentapp0_.t_sigdate as t15_1_, studentapp0_.t_major as t16_1_, studentapp0_.t_matriculate as t17_1_, studentapp0_.t_re as t18_1_ from student.dbo.t_studentApply studentapp0_
    Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not execute query
    at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:59)
    at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
    at org.hibernate.loader.Loader.doList(Loader.java:1596)
    at org.hibernate.loader.Loader.list(Loader.java:1577)
    at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:395)
    at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:271)
    at org.hibernate.impl.SessionImpl.list(SessionImpl.java:844)
    at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
    at com.student.po.StudentApplyPODAO.test(StudentApplyPODAO.java:68)
    at com.student.po.StudentApplyPODAO.main(StudentApplyPODAO.java:74)
    Caused by: java.sql.SQLException: Invalid column name t1_.
    at net.sourceforge.jtds.jdbc.JtdsResultSet.findColumn(JtdsResultSet.java:906)
    at net.sourceforge.jtds.jdbc.JtdsResultSet.getInt(JtdsResultSet.java:910)
    at org.apache.commons.dbcp.DelegatingResultSet.getInt(DelegatingResultSet.java:236)
    at org.hibernate.type.IntegerType.get(IntegerType.java:26)
    at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:77)
    at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:68)
    at org.hibernate.loader.Loader.getKeyFromResultSet(Loader.java:759)
    at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:292)
    at org.hibernate.loader.Loader.doQuery(Loader.java:412)
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:218)
    at org.hibernate.loader.Loader.doList(Loader.java:1593)
    ... 7 more
    这个是报错的异常
      

  2.   

    我吧数据全删了query.setFirstResult(1)这个又不报错了···
      

  3.   

      把数据全删了为什么setfirstresult(1)不报错呢??奇怪! setfirstresult不是指定索引的初始位置吗?是不是你数据库中开始的时候就因为1位置没有记录,所以你指向1的时候就会报错啊!建议再测试下!