day14:hibernate简单增删改查demo
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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的主要内容,如果未能解决你的问题,请参考以下文章