在单个应用程序中使用 NHibernate 处理多个数据库
目前,我在配置文件中定义连接属性,并且只连接到一个数据库。我希望能够在某个时候让用户登录,弄清楚(也许通过单独的中央数据库)他们应该连接哪个数据库,并且从那时起创建的所有会话都将与该数据库进行通信。
实现这一目标的最佳方法是什么。为每个可能的数据库创建一个配置文件?或者我可以有一个会话管理器并相应地动态更改连接 URL?我有哪些选择?
更新:抱歉,我应该提到这是 NHibernate。我认为这并不重要,但像 Hibernate Shards 这样的东西将不适用,因为我相信 NHibernate Shards 正在等待。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您只需创建两个数据源,然后调用特定查询所需的数据源。
请看一下:
https://www.hibernate.org/450.html
一些官方的解决方案。
在这里:
http://www.java-forums.org /database/159-hibernate-multiple-database.html
有关此问题的在线线程。
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.