Handling multiple databases with NHibernate in one application

At the moment I am defining connection properties in a config file and only ever connect to one database. I would like to be able to have a username at some point, figure out (via a separate central database, perhaps) which database they should connect, and from that point on all created sessions will talk to that database.

What is the best way to achieve this. Create a config file for every possible database? Or can I have one session manager and change the connection url accordingly? What options do I have?

Update: The apology I should have mentioned is NHibernate. I didn't think it would matter, but some things like Hibernate Shards won't apply as I believe NHibernate Shards is waiting.

+2


source to share


1 answer


You just need to make two datasources and then call the one you need for a specific request.

Please take a look at this:

https://www.hibernate.org/450.html

Some official solutions.



And here:

http://www.java-forums.org/database/159-hibernate-multiple-database.html

online question about this issue.

+2


source







All Articles