Handling Multiple databases with NHibernate in a single application

我的梦境 提交于 2019-12-07 21:05:49

问题


At the moment I define the connection properties in a configuration file and only ever connect to one database. I'd like to be able to at some point have a user login, figure out (via a seperate central database maybe) what database they should be connected and from that point on all sessions created will talk to that database.

Whats the best way to achieve this. Create a configuration file for every possible database? Or could I have a single session manager and change the connection url on the fly accordingly? What sort of options do i have?

Update: Apologies I should have mentioned this was NHibernate. I didn't think it would matter but some things like Hibernate Shards will not be applicable to be as I believe NHibernate Shards is waiting.


回答1:


You just need to make two datasources then call the one you need for the specific query.

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

an online thread about this issue.



来源:https://stackoverflow.com/questions/1470751/handling-multiple-databases-with-nhibernate-in-a-single-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!