Hibernate 与不同的数据库通信
我需要我的应用程序与两个不同的数据库通信,它们本身是复制的(使用 Postgres 流复制)。原因是我希望所有读取都针对一个数据库进行,而写入则针对另一个数据库。
我在我的应用程序中使用休眠。有没有一种开箱即用的方法来实现这一目标?
-谢谢
编辑:是的,请评论我想要实现的目标是否有意义。
I need my app to talk to two different databases, which themselves are replicated(using Postgres streaming replication). The reason is that I want to have all the reads happening against one database and writes against the other.
I use hibernate in my application. Is there an out of the box way to achieve this?
-thanks
edit: And yes, please comment on whether what I am trying to achieve makes sense.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Hibernate 支持分片。看看它是否对您有帮助: http://www.hibernate.org/subprojects/shards.html< /a>
如果您使用 spring 那么我知道有一种方法可以动态切换数据源。在此处查找更多信息
这是来自 stackoverflow 的类似问题:
在单个应用程序中使用 NHibernate 处理多个数据库
其他论坛讨论中的同类问题:
http://forum.springsource.org/showthread.php?t=12665
Hibernate supports sharding. See if it helps you: http://www.hibernate.org/subprojects/shards.html
If you are using spring then I know there is a way to dynamically switch the DataSource. Find more information here
This is a similar question from stackoverflow:
Handling Multiple databases with NHibernate in a single application
Also same kind of question in other forum discussion:
http://forum.springsource.org/showthread.php?t=12665
过去,我只是生成了两个会话工厂,一个用于只读工作块,一个用于读写工作块。我构建读写工厂,然后更改配置以具有不同的连接提供程序,并添加拦截器以捕获任何修改尝试并构建第二个。
这种方法的一个问题是 L2 缓存一致性,尽管这是 Hibernate 缓存和复制数据库的普遍问题。
In the past I've simply produced two session factories, and used one for read-only chunks of work and one for read-write chunks of work. I build the read-write factory, then change the configuration to have a different connection provider and add an interceptor to trap any modification attempts and build the second.
One problem with this approach is L2 cache coherence, although that's a general problem with both Hibernate caching and replicated databases.