(多数据源)使用hibernate+spring镜像数据
在Web应用程序中使用hibernate+spring+AS400数据库:
有3个数据源(每个地区一个),澳大利亚的DS,英国的DS和美国的DS。所有数据源中的架构都是相同的。
现在需要将数据持久化到数据源,规则是主区域(由最终用户使用 UI 选择)应始终用作主数据源来保存数据。此外,如果主要区域不是美国(假设用户选择英国区域),则数据应同时保存到英国数据源和美国数据源。
我知道打开所有会话工厂并手动管理所有内容的简单手动方法。 http://www.java-forums.org/database/867 -hibernate-multiple-databases.html
还有哪些其他可用的替代方案以及实现此目的的最佳方法?
Using hibernate+spring+AS400 database in a web application:
There are 3 datasources (one per region), DS for Australia, DS for UK and DS for USA. Schemas are the same in all the datasources.
Now data needs to be persisted to the datasource, rule is that the primary region (selected by the end user using UI) should always be used as primary datasource to save data. In addition, if the primary region is not USA (say user selected UK region) then data should be persisted to both UK datasource and USA datasource.
I am aware of a simple manual approach of opening all the session factories and managing everything manually.
http://www.java-forums.org/database/867-hibernate-multiple-databases.html
What are other alternates available and the best way to implement this ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它需要酸性吗?如果没有,我的第一个想法是添加一个 @PostPersist,它将实体添加到 JMS 主题,该主题由 3 个客户端读取,每个客户端代表一个数据库。然后,每个客户端将验证该实体是否已在其数据库中更新(例如,通过检查乐观锁定列)。
使用这种方法,您可能会遇到数据一致性问题,并且您需要针对每个客户端的每次故障采取行动。另一方面,您可以避免延迟(这就是为什么您首先有 3 个数据源的原因)。
但实际上,有几种可能的解决方案:-)
Does it needs to be ACID? If not, my first idea would be to add a @PostPersist which adds the entity to a JMS topic, which is read by 3 clients, each representing one database. Each client would, then, verify if the entity is already updated in its database (by checking the optimistic locking column, for instance).
With this approach you may have data consistency problems and you would need to act on each failure for each client. On the other hand, you'd avoid the latency (which is why you have 3 DataSources in the first place).
But really, there are several possible solutions :-)
系统级 (iSeries) 方法是启用澳大利亚和英国数据源到美国站点的远程日志记录,并让美国站点将日志更改应用到其本地 DB2。请注意,DB2/400 上的 SQL 源始终会记录日志(以提供承诺控制功能),因此您只需启用远程日志记录。有关此功能的概述,请转至 http://publib.boulder.ibm.com/infocenter/iseries/v5r3/index.jsp?topic=%2Fcl%2Fapyjrnchg.htm 或类似内容,具体取决于您的操作系统版本。
开发自己的应用日志更改的程序的另一种方法是使用打包的复制解决方案之一 - IBM DataReplicator、Vision Solutions 的 ODS/ODM 等。
a system-level (iSeries) approach would be to enable remote journaling of your Australia and UK data source to US site, and have USA site apply journal changes to its local DB2. Note that SQL sources on DB2/400 are always journaled (to provide commitment control capabilities) so you will just need to enable remote journaling. For an overview of this feature, go to http://publib.boulder.ibm.com/infocenter/iseries/v5r3/index.jsp?topic=%2Fcl%2Fapyjrnchg.htm or similar depending on your OS version.
An alternative to developing your own program that applies journal changes is to use one of the packaged replication solutions -- IBM DataReplicator, Vision Solutions' ODS/ODM, etc.