I am configuration my hibernate sessionfactory programmatically:
private static SessionFactory buildSessionFactory() {
// Create the SessionFactory from hibernate.cfg.xml
Configuration configuration = new Configuration();
configuration.configure();
configuration.setProperty("hibernate.connection.url", myUrl);
configuration.setProperty("hibernate.connection.username", myUser);
configuration.setProperty("hibernate.connection.password", myPass);
serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry();
return configuration.buildSessionFactory(serviceRegistry);
}
But problem, is that these properties are loaded only, when using hibernate operation from dao.
protected void startOperation() {
session = HibernateUtil.getSessionFactory().openSession();
tx = session.beginTransaction();
}
Therefore, when my application boots up, then hibernate.hbm2ddl.auto doesn’t seem to work. Can I somehow force hibernate.hbm2ddl.auto to start in my program or any other solution?
Suggetions or other options, thoughts?
You need to set hibernate.hbm2ddl.auto or used
Using configuration file like hibernate.properties or hibernate.cfg.xml is more preferred way to set your setting.