如何通过hibernate连接两个数据库
我需要能够确定在从应用程序登录时使用哪个数据库。这是一个旧代码,我被要求帮助修改基于Struts和hibernate。我需要根据用户详细信息决定在登录时连接到哪个数据库。但是我不确定如何继续实施这一点。我对这两种网络开发技术都很陌生,所以我仍在学习,根据我所拥有的书,我需要为每个数据库创建一个会话工厂。根据网络示例,此类问题已通过在应用程序中使用多数据库进行了解释,但我只需要在会话期间使用包含用户详细信息的数据库(详细信息存储在每个数据库中)。
I need to be able to determine which database to use at login time from an application. It's an old code I was asked to help modify based on Struts and hibernate. I need to decide, based on user details, which database to connect to at login time. However I am unsure as to how to proceed with implementing this. I'm new to the both web dev technologies so I'm still learning and according to the book I have I need to create one sessionfactory per dbase. Based on web examples, this sort of problem has been explained in terms of using multi-database within an application but I only need to use the one containing the user details for the duration of the session (details are stored on each database).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要每个数据库一个连接,每个数据库一个 EntityManager,以及嵌入其中的逻辑的代码,以找出使用每个数据库的适当环境。
You need one connection per database, one EntityManager per database, and code with logic embedded in it to figure out the appropriate circumstances under which each one is used.
对于完整的 hibernate-plugin-for-struts2。
检查一下:http://code.google.com/ p/full-hibernate-plugin-for-struts2/wiki/3b_Multiple_databases
For full-hibernate-plugin-for-struts2.
check this: http://code.google.com/p/full-hibernate-plugin-for-struts2/wiki/3b_Multiple_databases