longtengsoft 2009-02-16 19:19
浏览 374
已采纳

spring+hibernate query.list 报空指针

Hibernate: select count(*) as col_0_0_ from profession profession0_ where profession0_.dept_no=?
Hibernate: select top 12 profession0_.profession_No as profession1_1_, profession0_.profession_name as profession2_1_, profession0_.dept_no as dept3_1_ from profession profession0_ where profession0_.dept_no=? order by profession0_.profession_No desc
2009-2-16 19:10:01 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet default threw exception
java.lang.NullPointerException
at org.hibernate.tuple.AbstractEntityTuplizer.createProxy(AbstractEntityTuplizer.java:372)
at org.hibernate.persister.entity.AbstractEntityPersister.createProxy(AbstractEntityPersister.java:3121)
at org.hibernate.event.def.DefaultLoadEventListener.createProxyIfNecessary(DefaultLoadEventListener.java:232)
at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:173)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:87)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:862)
at org.hibernate.impl.SessionImpl.internalLoad(SessionImpl.java:830)
at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:266)
at org.hibernate.type.EntityType.resolve(EntityType.java:303)
at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:116)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:842)
at org.hibernate.loader.Loader.doQuery(Loader.java:717)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.doList(Loader.java:2145)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029)
at org.hibernate.loader.Loader.list(Loader.java:2024)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:375)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:308)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:153)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1106)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at com.top.daoHibernateImpl.HibernateGeneric.pagedQuery(HibernateGeneric.java:264)

    Assert.hasText(hql);
    Assert.isTrue(pageNo >= 1, "pageNo should start from 1");
    // Count查询
    String countQueryString = PageFactory.getTotalCountHqlByHql(hql);
    List countlist = this.find(countQueryString, values);
    int totalCount = ((Integer) countlist.get(0)).intValue();



    if (totalCount < 1) return new Page();
    // 实际查询返回分页对象
    Query query = createQuery(hql, values);
    int startIndex = PageFactory.getStartIndex(pageNo, pageSize);
    List results = query.setFirstResult(startIndex).setMaxResults(pageSize)
            .list();//本行报空指针
    return PageFactory.createPage(pageNo, pageSize, totalCount, results);

[b]问题补充:[/b]
大家好本问题已经解决!~
我才本站其他贴上看到了同样的贴,再此也谢谢那位仁兄!~

  • 写回答

1条回答 默认 最新

  • yighter 2009-02-16 22:51
    关注

    有没有可能起始行数过大?
    debug一下startIndex的值。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 需要跳转番茄畅听app的adb命令
  • ¥50 寻找一位有逆向游戏盾sdk 应用程序经验的技术
  • ¥15 请问有用MZmine处理 “Waters SYNAPT G2-Si QTOF质谱仪在MSE模式下采集的非靶向数据” 的分析教程吗
  • ¥50 opencv4nodejs 如何安装
  • ¥15 adb push异常 adb: error: 1409-byte write failed: Invalid argument
  • ¥15 nginx反向代理获取ip,java获取真实ip
  • ¥15 eda:门禁系统设计
  • ¥50 如何使用js去调用vscode-js-debugger的方法去调试网页
  • ¥15 376.1电表主站通信协议下发指令全被否认问题
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证