日期:2014-05-18  浏览次数:20919 次

请教hibernate中报空指针的问题
本人在看孙的hibernate   其中第2章的例子   在运行时报错
java.lang.NullPointerException
at   mypack.BusinessService.saveCustomer(BusinessService.java:54)
at   mypack.BusinessService.test(BusinessService.java:187)
at   mypack.BusinessService.main(BusinessService.java:197)
Exception   in   thread   "main "  

其中BusinessService.java如下
public   class   BusinessService   {
    public   static   SessionFactory   sessionFactory;
    static{
        try{
            //   Create   a   configuration   based   on   the   properties   file   we 've   put
            //   in   the   standard   place.
        Configuration   config   =   new   Configuration().configure();
        SessionFactory   sessionFactory   =   config.buildSessionFactory();


            //   Get   the   session   factory   we   can   use   for   persistence
            sessionFactory   =   config.buildSessionFactory();
        }catch(Exception   e){e.printStackTrace();}
    }

    public   void   findAllCustomers(ServletContext   context,OutputStream   out)   throws   Exception{
        //   Ask   for   a   session   using   the   JDBC   information   we 've   configured
        Session   session   =   sessionFactory.openSession();
        Transaction   tx   =   null;
        try   {
            tx   =   session.beginTransaction();
            List   customers=session.find( "from   Customer   as   c   order   by   c.name   asc ");
            for   (Iterator   it   =   customers.iterator();   it.hasNext();)   {
                  printCustomer(context,out,(Customers)   it.next());
            }

            //   We 're   done;   make   our   changes   permanent
            tx.commit();

        }catch   (Exception   e)   {
            if   (tx   !=   null)   {
                //   Something   went   wrong;   discard   all   partial   changes
                tx.rollback();
            }
            throw   e;
        }   finally   {
            //   No   matter   what,   c