1
我有HibernateUtil類和實體,servlet和jsp包。我應該添加到我的代碼或休眠的配置文件來啓動創建所有H2表(根據我的實體)部署在Tomcat我的戰爭文件之後,第一次調用之前(對我來說,這是登錄)如何在部署時使用Tomcat 8或9自動啓動Hibernate
public class HiberUtil {
private static final SessionFactory sFactory = configureSessionFactory();
private static SessionFactory configureSessionFactory() {
Configuration cf = new Configuration();
cf.configure("hibernate.cfg.xml");
SessionFactory sf = cf.buildSessionFactory(new StandardServiceRegistryBuilder().applySettings(cf.getProperties()).build());
return sf;
}
public static SessionFactory getSessionFactory() {
return sFactory;
}
public static void closeSessionFactory(){
sFactory.close();
}
}
我相信hbm2ddl-auto屬性是你在找什麼:http://stackoverflow.com/questions/438146/hibernate-hbm2ddl-auto-possible-values-and-what-they-do – Soggiorno