首页 > 代码库 > day14:hibernate简单增删改查demo

day14:hibernate简单增删改查demo

          Configuration cfg = new  Configuration().configure();

    SessionFactory  sf = cfg.buildSessionFactory();

         Session session = sf.openSession();

         session.beginTransaction();

    session.save();

         session.getTransaction().commit();

         session.close();

         sf.close();

 

 

       Configuration  cfg = new  Configuration().configure();

       SessionFactory  sf = cfg.buildSessionFactory();

       Session  session = sf.openSession();

       session.beginTransaction();

       session.update();

       session.getTransaction().commit();

       session.close();

       sf.close();

      

 

 

 

       Configuration  cfg = new  Configuration().configure();

   SessionFactory  sf = cfg.openSessionFactory();

       Session  session = sf.openSession();

       session.beginTransaction();

       session.delete();

       session.getTransaction().commit();

       session.close();

       sf.close();

 

 

       Configuration  cfg = Configuration().configure();

    SessionFactory  sf = cfg.openSessionFactory();

   Session  session = sf.openSession();

       session.findById();

       session.close();

       sf.close();

 

       手打了4遍hibernate执行代码块呀,哈哈方法很Low,加深印象吧

day14:hibernate简单增删改查demo