hunter_720 2008-06-20 18:26
浏览 373
已采纳

怪异的getHibernateTemplate().find()空指针问题

这个问题很怪.我在Junit下测试我的代码时,getHibernateTemplate().find()没有一点问题.当我把它放到Struts1.2的action下就报空指针异常.后来我改用Hibernate的session, 在query的时候还是出现同样的问题.关键只是在action中才出现,自己的测试代码中不出现.希望大家帮我看看.
异常如下:
exception
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)
org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
org.springframework.orm.hibernate3.HibernateTemplate$29.doInHibernate(HibernateTemplate.java:849)
org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:372)
org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:840)
org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:836)
com.ace.core.dao.impl.PersonDaoBean.getTPersonByName(PersonDaoBean.java:110)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source)
org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:304)
org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:172)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:139)
org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:107)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:161)
org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
$Proxy7.getTPersonByName(Unknown Source)
com.ace.core.business.impl.PersonManagerBean.login(PersonManagerBean.java:110)
com.ace.core.struts.action.LoginAction.execute(LoginAction.java:53)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)

这是我的applicationContext.xml:
[code="xml"]
<?xml version="1.0" encoding="UTF-8"?>
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">

class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">

hibernate.cfg.xml

























PROPAGATION_REQUIRED
PROPAGATION_REQUIRED
PROPAGATION_REQUIRED
PROPAGATION_REQUIRED
PROPAGATION_REQUIRED,readOnly











PROPAGATION_REQUIRED
PROPAGATION_REQUIRED
PROPAGATION_REQUIRED
PROPAGATION_REQUIRED
PROPAGATION_REQUIRED,readOnly











[/code]

PerManagerBean的Login方法:
[code="java"]
public Person login(String name, String password) {
TPerson tPerson = personDao.getTPersonByName(name);
String md5Password = "";
try {
md5Password = MD5HashUtil.hashCode(password);
if(!(tPerson.getPassword().equals(md5Password))){
return null;
}
TRole tRole = tPerson.getTRole();
if(tRole.getId() == 2){
AdminBean admin = getAdminResouce();
admin.setTPerson(tPerson);
return admin;
}else if(tRole.getId() == 3){
UserBean user = getUserResouce();
user.setTPerson(tPerson);
return user;
}else if(tRole.getId() == 1){
SuperAdminBean superAdmin = getSuperAdminResouce();
superAdmin.setTPerson(tPerson);
return superAdmin;
}
} catch (NoSuchAlgorithmException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
[/code]

PersonDaoBean的getTPersonByName方法:
[code="java"]
public TPerson getTPersonByName(String name){
List list = getHibernateTemplate().find("from TPerson tp where tp.name=?",name);
if(list.size() != 0){
TPerson tPerson = (TPerson) list.get(0);
return tPerson;
}else
return null;
}
[/code]

  • 写回答

2条回答 默认 最新

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥20 有人知道怎么将vsi格式的图片文件,转换为svs格式的文件吗
      • ¥15 历史模拟法计算var实验报告
      • ¥15 白鲸算法优化K值的VMD分解出错
      • ¥20 写一个基于52单片机用hc-05蓝牙模块控制28BYJ-48步进电机进行旋转,在手机蓝牙串口输入1019电机转半圈,输入2038电机转一圈,输入0复位的代码吗
      • ¥15 求51单片机8位数码管计时器程序
      • ¥20 matlab识别螺母边缘
      • ¥15 python 6x6游戏加登录、记录系统
      • ¥100 基于做一个模拟智慧路灯
      • ¥15 ME21N 创建采购成功并且生成采购订单号,但显示“快件文档更新已取消”,SM13看错误提示为如下截图:
      • ¥30 android 集成fmod实现变声功能中遇到的问题