首页 新闻 会员 周边 捐助

ssh2博客 多表查询

0
悬赏园豆:5 [已关闭问题]

在hibernate多表查询中,都出错,虽有执行

Hibernate: select article0_.aid as aid0_, article0_.tid as tid0_, article0_.uid as uid0_, article0_.title as title0_, article0_.content as content0_, article0_.exam as exam0_, article0_.blushtime as blushtime0_, article0_.readCount as readCount0_ from t_article article0_  但是返回却是null。
DAO中实现

public List<Article> queryAll() throws Exception {
  List<Article> list=(List<Article>) getHibernateTemplate().find("FROM Article");
  if(list==null){
   System.out.print("null list");
   return null;
  }
  return list;
 }

service层就调用,

Action层:

public String queryAll(){
  try {
   articleList=(List<Article>)articleService.queryAll();
  } catch (Exception e) {
   return "queryAllFail";
  }
  return "queryAllSuc";
 }

总是返回queryAllFail 到错误页面。

希望大家帮忙解决!谢谢

问题补充: 做Hibernate多对一查询时,一方查询正常,但多方查询出错.出错的异常信息为: java.lang.NullPointerException org.hibernate.tuple.AbstractEntityTuplizer.createProxy(AbstractEntityTuplizer.java:372) org.hibernate.persister.entity.AbstractEntityPersister.createProxy(AbstractEntityPersister.java:3121) org.hibernate.event.def.DefaultLoadEventListener.createProxyIfNecessary(DefaultLoadEventListener.java:232) org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:173) org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:87) org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:862) org.hibernate.impl.SessionImpl.internalLoad(SessionImpl.java:830) org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:266) org.hibernate.type.EntityType.resolve(EntityType.java:303) org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:116) org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:842) org.hibernate.loader.Loader.doQuery(Loader.java:717) org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224) org.hibernate.loader.Loader.doList(Loader.java:2145) org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029) org.hibernate.loader.Loader.list(Loader.java:2024) org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:375) org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:308) org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:153) org.hibernate.impl.SessionImpl.list(SessionImpl.java:1106) 解决方案是: 1.导入cglib-2.2并替换掉cglib-2.13 2.将其关联的对象设置成lazy="false"
小跃的主页 小跃 | 初学一级 | 园豆:175
提问于:2009-12-22 01:01
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册