How to change hibernate settings on runtime

One is you can build your configuration from scratch but what I like to do is getting the standard settings from my hibernate.cfg.xml file then change some of the values on my code. here’s how I do it

Configuration conf = new Configuration();
conf.configure().setProperty(“hibernate.connection.url”, “jdbc:mysql://”+host+”/”+dbname);
conf.setProperty(“hibernate.connection.username”, user);
conf.setProperty(“hibernate.connection.password”, password);

One Response to “How to change hibernate settings on runtime”

  1. Garry Says:

    Just remember that if you are using Hibernate Reverse Engineering then the .hbm.xml file might contain a direct ref to the Catalog. This will override any settings changed within the property.

    To fix this you need to remove the Catalog ref within your hbm.xml files…

Leave a Reply