封装hibernate

private static SessionFactory sf;
static{
Configuration cfg=new Configuration().configure();
ServiceRegistry sr=new ServiceRegistryBuilder()
.applySettings(cfg.getProperties())
.buildServiceRegistry();
sf=cfg.buildSessionFactory(sr);
}
public static Session getCurrentSession(){
return sf.getCurrentSession();
}
public static void beginTransaction(){
getCurrentSession().beginTransaction();
}
public static void commit(){
getCurrentSession().getTransaction().commit();
}
public static void rollback(){
getCurrentSession().getTransaction().rollback();
}

原文地址:https://www.cnblogs.com/dawn-and-night/p/6713739.html