I need to have multiple databases for different customers. How can I handle multiple databases with Hibernate? Are there any good examples how to do this?
I could create Configuration object and then build SessionFactory, but that would create always a new session factory which wouldn’t be very wise.
EDIT:
Now I can get hibernate Configuration object when user logs in, but how can I create/get session factory with that object so that there would be only one session factory for one database (of course if multiple databases are used at the same time, then there can be more than one session factory)?
You’ll have indeed to create multiple
SessionFactory(one per database).Use some unique
Map<SomeKey, SessionFactory>. If aSessionFactoryhasn’t been created yet, build it and store it in the map.