public class HibernateUtil { private static final ThreadLocal<Session> threadLocal = new ThreadLocal<Session>(); private static SessionFactory sessionFactory = null; private static Session session; private static Transaction transaction; static { try { Configuration cfg = new Configuration().configure(); ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(cfg.getProperties()).build(); sessionFactory = cfg.buildSessionFactory(serviceRegistry); session=sessionFactory.openSession(); transaction=session.beginTransaction(); } catch (Exception e) { System.out.print("创建会话工厂失败"); } }
ansaction()
;
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/11248.html