数据库有数据,但就是查询不到,用的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)

解决方案 »

  1.   

    at com.hr.platform.dao.BaseHibernateDao.queryAllEntity(BaseHibernateDao.java:63)看看这里,哪个参数为空了。话说你根本没贴出BaseHibernateDao.queryAllEntity的代码...
      

  2.   

    这就是最底层的了,用的ssh框架啊
      

  3.   

    还有一点,我的主键是不连续的,用hibernate 查询会报错吗
      

  4.   

    AuthorityDaoImpl这个类应该是你自己开发的吧,起码把它里面的queryAllEntity方法贴出来啊
      

  5.   

    注入了啊,是不是事务的问题,
    <!-- 配置事务管理器 -->
    <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory"></property>
    </bean>
    <!-- 配置传播事务特性 -->
    <tx:advice id="txAdvice"  transaction-manager="transactionManager">
    <tx:attributes>
    <!-- 对修改数据的方法添加的事务 -->
    <tx:method name="save*" propagation="REQUIRED"/>
    <tx:method name="modify*" propagation="REQUIRED"/>
    <tx:method name="update*" propagation="REQUIRED"/>
    <tx:method name="delete*" propagation="REQUIRED"/>
    <!-- 对查询的方法添加的事务,添加read-only属性为true提升效率 -->
    <tx:method name="get*" propagation="SUPPORTS" read-only="true"/>
    <tx:method name="query*" propagation="SUPPORTS" read-only="true"/>
    <tx:method name="load*" propagation="SUPPORTS" read-only="true"/>
    <tx:method name="find*" propagation="SUPPORTS" read-only="true"/>
    </tx:attributes>
    </tx:advice>
    <aop:config>
    <aop:pointcut id="allManagerMethod"
    expression="execution (* com.hr.*.dao.impl.*.*(..))" />
    <aop:advisor advice-ref="txAdvice" pointcut-ref="allManagerMethod" />

    </aop:config>
    <aop:config>
    <aop:pointcut id="platallManagerMethod"
    expression="execution (* com.hr.*.dao.*.*(..))" />
    <aop:advisor advice-ref="txAdvice" pointcut-ref="platallManagerMethod" />

    </aop:config>
    <aop:aspectj-autoproxy proxy-target-class="true" />
      

  6.   

    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();}
    }
    }AuthorityDaoImpl authorityDaoImpl=new AuthorityDaoImpl();没住人啊 你直接new出来的  不是通过spring得到的 spring懒得管你 
      

  7.   

    没注入  你果断打个断点 看看this.getHibernateTemplate().是不是null