Aguo_C 2008-07-26 19:02
浏览 907
已采纳

Hibernate 查询出现空指针异常?

在用Hibernate进行数据关联查询时总是出现空指针异常,
[code="java"]
public List queryAll() throws Exception {
List all = null;
String hql = "FROM Emp";
Query q = this.session.createQuery(hql);
all = q.list();
this.session.close();
return all;
}
[/code]

进行测试出现空指针异常,提示all = q.list();有错!
请问大家是否遇到过此类问题呢?
要怎么解决呢?

[code="java"]
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Hibernate: select emp0_.empno as empno, emp0_.deptno as deptno1_, emp0_.ename as ename1_, emp0_.eage as eage1_, emp0_.esex as esex1_ from hibernate.emp emp0_ where emp0_.empno=?
Exception in thread "main" java.lang.NullPointerException
at org.hibernate.tuple.AbstractTuplizer.createProxy(AbstractTuplizer.java:249)
at org.hibernate.persister.entity.BasicEntityPersister.createProxy(BasicEntityPersister.java:2831)
at org.hibernate.event.def.DefaultLoadEventListener.createProxyIfNecessary(DefaultLoadEventListener.java:218)
at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:163)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:79)
at org.hibernate.impl.SessionImpl.internalLoad(SessionImpl.java:655)
at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:261)
at org.hibernate.type.EntityType.resolve(EntityType.java:286)
at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:105)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:530)
at org.hibernate.loader.Loader.doQuery(Loader.java:436)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:218)
at org.hibernate.loader.Loader.doList(Loader.java:1593)
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 org.zhg.impl.EmpDAOImpl.queryByEmpno(EmpDAOImpl.java:54)
at org.zhg.test.EmpTest.main(EmpTest.java:20)

[/code]

  • 写回答

2条回答 默认 最新

  • hglxr 2008-07-27 12:02
    关注

    好像是hibernate本身的代理出了问题,如果你设置了lazy= true,改成lazy=false试试!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 用verilog实现tanh函数和softplus函数
  • ¥15 求京东批量付款能替代天诚
  • ¥15 slaris 系统断电后,重新开机后一直自动重启
  • ¥15 51寻迹小车定点寻迹
  • ¥15 谁能帮我看看这拒稿理由啥意思啊阿啊
  • ¥15 关于vue2中methods使用call修改this指向的问题
  • ¥15 idea自动补全键位冲突
  • ¥15 请教一下写代码,代码好难
  • ¥15 iis10中如何阻止别人网站重定向到我的网站
  • ¥15 滑块验证码移动速度不一致问题