0

我正在尝试从数据库中查询它的休眠项目

public class FeedInputParamsDaoImpl implements IFeedInputParamsDao {
 @Autowired
private SessionFactory sessionFactory;

public void setSessionFactory(SessionFactory sessionFactory) {
    this.sessionFactory = sessionFactory;
}

private int BATCH_SIZE = 50;

public Session getSession() {
/*null pointer exception*/Session session = sessionFactory.openSession();
    return session;
}
      @Override
public List<FeedInputParams> getAllFeedInputParamslist (int feedKey) {
    String queryString = "from FeedInputParams as feedInputParams where feedInputParams.feedKey > ?";
    Session session =  getSession();
    Query query = session.createQuery(queryString);
    query.setParameter(0, feedKey);
    List<FeedInputParams> feedInputParamsList = query.list();
    return feedInputParamsList;
}

}

而这个getAllFeedInputParamslist(int feedKey)是从方法中调用的

  public void readFile()
        throws Exception {  
    FeedInputParamsDaoImpl feedInputParamsDaoImpl=new FeedInputParamsDaoImpl();
    List<FeedInputParams> feedInputParamsList=feedInputParamsDaoImpl.getAllFeedInputParamslist(0);
    System.out.println("feedInputParamsList...."+feedInputParamsList);

}

我收到空指针异常

java.lang.NullPointerException at com.vxl.appanalytix.dao.impl.FeedInputParamsDaoImpl.getSession(FeedInputParamsDaoImpl.java:28) 
 at com.vxl.appanalytix.dao.impl.FeedInputParamsDaoImpl.getAllFeedInputParamslist(FeedInputParamsD0Impl.java:44) 
at
4

1 回答 1

0

SessionFactory 为空 - 由于某种原因,它没有被 spring 自动装配。您对 FeedInputParamsDaoImpl 类有任何注释吗?

于 2013-04-20T09:09:01.810 回答