定义一个工具种获取SessionFactory或Session对象

定义一个工具类获取SessionFactory或Session对象public final class HibernateUtil{private SessionFactor

定义一个工具类获取SessionFactory或Session对象

public final class HibernateUtil{private SessionFactory sessionFactory;private HibernteUtil(){}static{Configuration cfg = new Configuration();cfg.configure();sessionFactory = cfg.buildSessionFactory();}public static SessionFactory sessionFactory(){return sessionFactory;}public static Session getSession(){return sessionFactory.openSession();}}

?如果配置文件不叫hibernate.cfg.xml则在cfg.configure("hibernate.xml")中指定,默认在classpath路径下找。