会话工厂处理多个数据库连接

发布于 2024-12-24 17:54:28 字数 151 浏览 0 评论 0原文

我的任务是为不同的数据源创建多个会话工厂。一个数据源将用于读取请求,另一个数据源将用于读写请求。

我们的数据库服务(DAO 的包装)的每个 API 都作为事务执行。单个 API 可以调用具有不同读/写属性的多个 DAO 函数。

执行此任务的最佳方法是什么?

I have a task to create multiple session factories for different Data Sources. One data source will be used for read requests and another for read-write requests.

Each API of our Database Service(a wrapper over DAO) is executed as a transaction. Single API may call multiple DAO functions having different Read/Write property.

What is the best possible way to perform this task?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

千柳 2024-12-31 17:54:28

我假设不同的数据源是不同的数据库。否则,您可以使用带有 @Transactional 注释的 readOnly 属性来管理只读事务。

您可以在 DAO 层中注入两个独立的会话工厂来管理这些事务。或者,您可以使用 AbstractRoutingDataSource。请参阅此处的文章

I am assuming that the different datasources are different DBs . Else you could use the readOnly attribute with the @Transactional annotation to manage the read only transactions.

You could inject two separate session factories in the DAO layer to manage these transactions . Alternatively , you could use AbstractRoutingDataSource . See a write up on this here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文