We had a similar need. Effectively, we had username/pwd settings in a separate config file and didn't want them to be redundant in the hibernate.cfg.xml.
To accomplish this, it looks something like:
Configuration cfg = new Configuration().configure(<hibernate.cfg.xml>);
cfg.setProperty("connection.url", ...);
cfg.setProperty("connection.username", ...);
cfg.setProperty("connection.password", ...);
cfg.setProperty("hibernate.connection.url", cfg.getProperty("connection.url"));
cfg.setProperty("hibernate.connection.username", cfg.getProperty("connection.username"));
cfg.setProperty("hibernate.connection.password", cfg.getProperty("connection.password"));
hibernateSessionFactory = cfg.buildSessionFactory();
-----------------------
The trick is in knowing what properties need to be set.
|