We have a Java-Hibernate based web application in which we deal with PostgreSQL database.(It is a single database having multiple schema(s) in it.)
Currently we are facing scalability issues so we have decided to split our schema(s) among multiple database.
Example:
Problem:
Note: It would be great, if anyone can provide tutorial/document link for this.
Similar Question: Hibernate using multiple databases
(I am expecting similar kind of answer but without multiple cfg.xml :( )
Ok, so your requirement is not
only one hibernate config file
but to be able to
create new sessionFactory without stopping the server.
The code in the question you referenced is looking like :
Configuration config = new Configuration().configure("<complete path to your cfg.xml file>");
SessionFactory sessionFactory = config.buildSessionFactory();
AS you can see you have a config object first, before getting a sessionFactory. Just fiddle with it in the code before buiding the session factory :
Configuration config = new Configuration().configure("<complete path to your cfg.xml file>");
config.setProperty("datasource", new_datasource_to_the_new_database)
SessionFactory sessionFactory = config.buildSessionFactory();
"datasource"
key by the actual key you are using in the current hibernate.cfg.xml file so that is overrides it. Build new data source, the same way you are building it currently, pointing to the new database.