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