Hello,
I am trying to change the default configuration(in hibernate.cfg.xml) after calling configure(). The parameters get set, but they don't have any effect when the SessionFactory is build.
Code
Code:
if(cfg == null){
cfg = new Configuration().configure();
// Check if there are database connections settings defined in
// the preference node
cfg.setProperty("hibernate.connection.driver_class",
Settings.s.get(Settings.DATABASE_DRIVER,
cfg.getProperty("hibernate.connection.driver_class")
)
);
cfg.setProperty("hibernate.connection.url",
Settings.s.get(Settings.DATABASE_URL,
cfg.getProperty("hibernate.connection.url")
)
);
cfg.setProperty("hibernate.connection.username",
Settings.s.get(Settings.DATABASE_USERNAME,
cfg.getProperty("hibernate.connection.username")
)
);
cfg.setProperty("hibernate.connection.password",
Settings.s.get(Settings.DATABASE_PASSWORD,
cfg.getProperty("hibernate.connection.password")
)
);
cfg.setProperty("show_sql",
userPrefs.get("show_sql",
cfg.getProperty("show_sql")
)
);
cfg.setProperty("dialect",
Settings.s.get(Settings.DATABASE_DIALECT,
cfg.getProperty("dialect")
)
);
log.debug("Registry: " + Settings.s.get(Settings.DATABASE_DRIVER,
// Prints correct values cfg.getProperty("hibernate.connection.driver_class")
));
log.debug("Starting with [database.url]: " + cfg.getProperty("hibernate.connection.url"));
log.debug("Starting with [database.driver_class]: " + cfg.getProperty("hibernate.connection.driver_class"));
log.debug("Starting with [database.username]: " + cfg.getProperty("hibernate.connection.username"));
log.debug("Starting with [database.password]: " + cfg.getProperty("hibernate.connection.password"));
log.debug("Starting with [database.dialect]: " + cfg.getProperty("dialect"));
}
// Not configured with values from registry but with settings from default config file
SessionFactory sf = cfg.buildSessionFactory();
Question
Is it possible to first create a default config from a hibernate.cfg.xml and then change it settings?