SSH泛型basedao<T>执行根据ID查询时空指针异常,求解答
publicclassHrJobPublishActionextendsActionSupportimplementsSessionAware{privateHrJobP...
public class HrJobPublishAction extends ActionSupport implements SessionAware {
private HrJobPublishService hrJobPublishService;
action中已注入service
调用service中根据ID查询方法:
HrJobPublish hjp = hrJobPublishService.queryHjpById(1);
public class HrJobPublishServiceImpl implements
HrJobPublishService {
private HrJobPublishDao hrJobPublishDao;
public HrJobPublish queryHjpById(int id) {
return hrJobPublishDao.queryById(id);
}
service中已注入hrJobPublishDao
然后hrJobPublishDao继承了BaseDao:
public interface HrJobPublishDao extends BaseDao<HrJobPublish>{}
BaseDao中:
public class BaseDaoImpl<T> extends HibernateDaoSupport implements BaseDao<T>{
private Class<T> entityClass;
public T queryById(Integer id) {
return this.getHibernateTemplate().get(entityClass, id);
}
}
到此执行该方法的时候
页面显示:
HTTP Status 500 -
type Exception report
message
description The server encountered an internal error () that
prevented it from fulfilling this request.
exception java.lang.NullPointerException
org.hibernate.impl.SessionImpl.get(SessionImpl.java:836)
org.springframework.orm.hibernate3.HibernateTemplate$1.doInHibernate(HibernateTemplate.java:519)
org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:406)
...........调试过程进入baseDao的时候,id还是有值的。但仍然报空指针异常,为什么呢?求解答 展开
private HrJobPublishService hrJobPublishService;
action中已注入service
调用service中根据ID查询方法:
HrJobPublish hjp = hrJobPublishService.queryHjpById(1);
public class HrJobPublishServiceImpl implements
HrJobPublishService {
private HrJobPublishDao hrJobPublishDao;
public HrJobPublish queryHjpById(int id) {
return hrJobPublishDao.queryById(id);
}
service中已注入hrJobPublishDao
然后hrJobPublishDao继承了BaseDao:
public interface HrJobPublishDao extends BaseDao<HrJobPublish>{}
BaseDao中:
public class BaseDaoImpl<T> extends HibernateDaoSupport implements BaseDao<T>{
private Class<T> entityClass;
public T queryById(Integer id) {
return this.getHibernateTemplate().get(entityClass, id);
}
}
到此执行该方法的时候
页面显示:
HTTP Status 500 -
type Exception report
message
description The server encountered an internal error () that
prevented it from fulfilling this request.
exception java.lang.NullPointerException
org.hibernate.impl.SessionImpl.get(SessionImpl.java:836)
org.springframework.orm.hibernate3.HibernateTemplate$1.doInHibernate(HibernateTemplate.java:519)
org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:406)
...........调试过程进入baseDao的时候,id还是有值的。但仍然报空指针异常,为什么呢?求解答 展开
3个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询