突然发现自己连最原始的Hibernate获取Session的方法都忘了,特此贴上,以备忘
hibernate.cfg.xml在src下时
指定hibernate.cfg.xml位置的方式
hibernate.cfg.xml在src下时
Configuration configuration = new Configuration();
SessionFactory sessionFactory = configuration.buildSessionFactory();
Session session = sessionFactory.openSession();
指定hibernate.cfg.xml位置的方式
Configuration configuration = new Configuration().configure("xxx");
SessionFactory sessionFactory = configuration.buildSessionFactory();
Session session = sessionFactory.openSession();