buildSessionFactory过时解决方案

 1 public void test() {  
 2         Configuration cfg = new Configuration();  
 3         cfg.configure();          
 4         ServiceRegistry  sr = new ServiceRegistryBuilder().applySettings(cfg.getProperties()).buildServiceRegistry();           
 5         SessionFactory sf = cfg.buildSessionFactory(sr);  
 6                   
 7           
 8         Session session = sf.openSession();  
 9         Transaction tx = session.beginTransaction();  
10         User user = new User();  
11         user.setBirthday(new Date());  
12         user.setName("neal");  
13           
14         session.persist(user);  
15         tx.commit();  
16         session.close();  
17         System.out.println("end");  
18     }  

 

posted @ 2013-03-18 16:08  daveztong  阅读(555)  评论(0编辑  收藏  举报