当前位置: 代码迷 >> Java Web开发 >> 跪求高手解决ssh有关问题
  详细解决方案

跪求高手解决ssh有关问题

热度:5352   发布时间:2013-02-25 21:18:10.0
跪求高手解决ssh问题
数据库有数据,但就是查询不到,用的sqlserver2005,
代码如下:

public T queryEntity(T t,Serializable id) throws Exception{
try{
return (T) this.getHibernateTemplate().load(Class.forName(t.getClass().getName()), id);

}catch(RuntimeException e){
logger.error("查询实体异常"+t.getClass().getName(),e);
throw e;
}
}


测试类:
public class Test {
public static void main(String[] args) {
Function function =new Function();
AuthorityDaoImpl authorityDaoImpl=new AuthorityDaoImpl();
try {
authorityDaoImpl.queryAllEntity(function);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();

}
}
}



报如下错误:


log4j:WARN No appenders could be found for logger (com.hr.platform.dao.BaseHibernateDao).
log4j:WARN Please initialize the log4j system properly.
java.lang.NullPointerException
at com.hr.platform.dao.BaseHibernateDao.queryAllEntity(BaseHibernateDao.java:63)
at com.hr.authority.test.Test.main(Test.java:11)


------解决方案--------------------------------------------------------
at com.hr.platform.dao.BaseHibernateDao.queryAllEntity(BaseHibernateDao.java:63)

看看这里,哪个参数为空了。

话说你根本没贴出BaseHibernateDao.queryAllEntity的代码...
------解决方案--------------------------------------------------------
AuthorityDaoImpl这个类应该是你自己开发的吧,起码把它里面的queryAllEntity方法贴出来啊
------解决方案--------------------------------------------------------
sessionFactory没有注入?
------解决方案--------------------------------------------------------
Java code
public class Test {public static void main(String[] args) {Function function =new Function();AuthorityDaoImpl authorityDaoImpl=new AuthorityDaoImpl();try {authorityDaoImpl.queryAllEntity(function);} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();}}}
  相关解决方案