在用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]