sjhyam wrote:
2nd option: When you configure Hibernate from HibernateUtil class, you have to manually load the configuration (hiberbate.cfg.xml) per environment. Then you have to maintain 3 different files like hibernate_dev.cfg.xml, hibernate_test.cfg.xml and hibernate_stage.cfg.xml (I hate this one!!!!)
This looks like it will work best for me, based on my needs. However, it will lead to many config files that must be managed
and they will be the same (apart from the DB connect data and 1 or 2 props). I hate this too!
Something more maintainable would be a way to overlay properties/config. I.E. Load a general default config file and update a few properties...
sjhyam wrote:
Other option: Just maintain one configuration file. But in your HibernateUitl class, when load the configuration supply the database properties.
Code:
Configuration cfg = new Configuration().configure();
cfg.setProperty(Environment.URL, "dbURL");
cfg.setProperty(Environment.user, "user");
cfg.setProperty(Environment.password, "password");
This looks interesting. Can I do something like this (assuming valid files, paths, etc.)?
Code:
String env = System.getProperty("db.env");
Configuration cfg = new Configuration().configure("default.cfg.xml");
cfg.configure("db-" + env + ".properties");
Thanks!