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();
}
时间: 2024-10-04 03:29:20