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 @   daveztong  阅读(555)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示