buildSessionFactory()
Configuration config = new Configuration().configure(); //建立Configuration物件 SessionFactory sessionFactory = config.buildSessionFactory();
private static SessionFactory factory = null; //SessionFactory物件 static{ //靜態塊 try{ Configuration cfg = new Configuration().configure(); //載入Hibernate組態檔 cfg.addClass(Users.class); //載入實體類 System.out.println("成功的載入了實體類Users"); factory = cfg.buildSessionFactory(); //範例化SessionFactory System.out.println("成功的建立了SessionFactory範例"); }catch(HibernateException e){ e.printStackTrace(); } }執行結果如下: