java - hibernate - how to change properties at runtime -


i trying change properties in hibernate.cfg.xml code doesn't work.

public static void changeconfiguration(string login, string password){     configuration cfg = new configuration();     cfg.configure();     cfg.setproperty("hibernate.connection.password", password);     cfg.setproperty("hibernate.connection.username", login);   } 

any idea why thats doesnt work? file hibernate.cfg.xml looks same.

to make work, should build sessionfactory configuration object , use sessionfactory session.

something :

public static sessionfactory changeconfiguration(string login, string password){     configuration cfg = new configuration();     cfg.configure();     cfg.setproperty("hibernate.connection.password", password);     cfg.setproperty("hibernate.connection.username", login);      sessionfactory sessionfactory = cfg.buildsessionfactory();     return sessionfactory; } 

but @ end, not change hibernate.cfg.xml file, overwrite or defines properties @ runtime. if don't want put username , password in hibernate.cfg.xml file, should use .properties file contain these values.


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -