haodiao
2009-06-17 17:33 阅读 199
已采纳

ssh的一个问题 配置了多对一关联getHibernateTemplate为空

是这样的,加了配置关联关系出现异常信息,把关联关系删除了就没有了异常信息。
我用ssh的时候我有个
产品表实体映射文件,配置与产品类别了多对一,
下面是产品配置关联
[code="java"]
column="typeId"
class="com.wxb.cniny.product.model.ProtypeEntity">

[/code]
产品类别
[code="java"]





[/code]
dao类
[code="java"]
public List list(String hql) {
// TODO Auto-generated method stub
List list=null;
try{
list = getHibernateTemplate().find(hql);//配置关联关系出现null引用
logger.debug("ssuccess");
}catch(Exception e){
e.printStackTrace();
logger.error("select fail", e);
}
return list;
}[/code]
红色那出现了
NullPointerException:
信息如下:
Hibernate: select this_.proId as proId5_0_, this_.proName as proName5_0_, this_.price as price5_0_, this_.proImagepath as proImage4_5_0_, this_.proRemark as proRemark5_0_, this_.useMethod as useMethod5_0_, this_.producExcet as producEx7_5_0_, this_.facade as facade5_0_, this_.odor as odor5_0_, this_.PHValue as PHValue5_0_, this_.specific gravity as specific11_5_0_, this_.boiling point as boiling12_5_0_, this_.solubility index as solubility13_5_0_, this_.productInfo as product14_5_0_, this_.Packsize as Packsize5_0_, this_.fixedYear as fixedYear5_0_, this_.typeId as typeId5_0_ from kyldb.productinfo this_
2009-6-17 16:11:15 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet action 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.criteria.CriteriaLoader.list(CriteriaLoader.java:94)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1533)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)
at com.wxb.comm.impl.ComDAOImpl.createCriteria(ComDAOImpl.java:176)
at com.wxb.cniny.product.dao.impl.ProductDAOImpl.getAllRowCount(ProductDAOImpl.java:52)
at com.wxb.cniny.product.service.impl.ProductServiceImpl.queryForPage(ProductServiceImpl.java:40)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:304)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:139)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:107)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:161)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at $Proxy5.queryForPage(Unknown Source)
at com.wxb.struts.action.ProductAction.doGetAll(ProductAction.java:114)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:274)
at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:194)
at org.springframework.web.struts.DelegatingActionProxy.execute(DelegatingActionProxy.java:106)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
....
我把配置的关联关系删除了,就不会出现问题。请问这是怎么回事?
[b]问题补充:[/b]
lazy="false"也试过,还是不行。
这是hql语句,String hql = " from ProductEntity";

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

4条回答 默认 最新

  • 已采纳
    wanghaolovezlq wanghaolovezlq 2009-06-17 17:38

    我估计应该是你执行的hql被lazy="true"影响到了
    改成lazy="false"试看看

    点赞 评论 复制链接分享
  • laitaogood laitaogood 2009-06-17 17:45

    LZ发配置文件来看看
    因为默认的是延迟加载的,可能因为这个而出问题

    点赞 评论 复制链接分享
  • xiaoxiaohai22 xiaoxiaohai22 2009-06-17 19:12

    我也是刚该是学习,你的hql语句是什么呢?没有啊
    在就是延迟加载的问题 lazy="false"

    点赞 评论 复制链接分享
  • wanghaolovezlq wanghaolovezlq 2009-06-18 08:54

    你把这条sql放到数据库去执行下看有没数据

    select this_.proId as proId5_0_, this_.proName as proName5_0_, this_.price as price5_0_, this_.proImagepath as proImage4_5_0_, this_.proRemark as proRemark5_0_, this_.useMethod as useMethod5_0_, this_.producExcet as producEx7_5_0_, this_.facade as facade5_0_, this_.odor as odor5_0_, this_.PHValue as PHValue5_0_, this_.specific gravity as specific11_5_0_, this_.boiling point as boiling12_5_0_, this_.solubility index as solubility13_5_0_, this_.productInfo as product14_5_0_, this_.Packsize as Packsize5_0_, this_.fixedYear as fixedYear5_0_, this_.typeId as typeId5_0_ from kyldb.productinfo this_

    点赞 评论 复制链接分享

相关推荐