首页 > 代码库 > 封装hibernate

封装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();
}

封装hibernate