在Hibernate中同时使用两个数据库 [英] Use two databases concurrently in Hibernate

查看:88
本文介绍了在Hibernate中同时使用两个数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须通过mysql一起使用多个数据库(在相同的连接上...)。我想使用休眠,但我可以找到周围是使用两个sessionfactories。现在的问题是:如何在不同的sessionfactor中执行像一对多的映射...似乎不可能,因为我必须将映射放在一个配置中,并且我无法传播它......任何建议?

解决方案

您可能会使用Hibernate Shards $ b

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



这里有一些快速信息。


Hibernate Shards是由Google开发并捐赠的子项目。它允许跨越不同数据库(或用户)管理多个SessionFactory实例,可选择使用原型配置创建。



$ b 优点:一个预先制定的解决方案。

缺点:不适用于大量模式,因为每个数据库用户/模式有效一个SessionFactory。


I've to use more than one database together (on the same connection... ) via mysql. I want to use hibernate, but all I can find around is to use two sessionfactories. Now the problem is: how can I do mappings like one-to-many among different sessionfactories... seems not possible as I have to put mapping in one configuration and I can't spread it ... Any suggestion?

解决方案

You might use Hibernate Shards

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

Here is some quick info

Hibernate Shards is a subproject developed and donated by Google. It allows the management of several SessionFactory instances across different databases (or users), optionally created from a "prototype" configuration.

Pros: A pre-made solution.

Cons: Not appropriate for large numbers of schemas since there is effectively one SessionFactory per database user/schema.

这篇关于在Hibernate中同时使用两个数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆