hibernate4以后SessionFactory对像的生成。
由于4.0版本以后就把原来用于生成SessionFactory的buildSessionFactory()方法给废弃了,现在可以用以下方法解决:
User user=new User();
Configuration cfg = new Configuration();
cfg.configure();
ServiceRegistry serviceRegistry =new ServiceRegistryBuilder().applySettings(cfg.getProperties()).buildServiceRegistry();
SessionFactory sf = cfg.configure().buildSessionFactory(serviceRegistry);
Session session = sf.openSession();
session.beginTransaction();
session.save(user); //保存对象
session.getTransaction().commit();
session.close();
sf.close();