会话工厂以处理多个数据库连接 [英] Session factories to handle multiple DB connections
问题描述
我的任务是为不同的数据源创建多个会话工厂。一个数据源将用于读取请求,另一个数据源用于读写请求。
我们的数据库服务的每个API(DAO的包装器)都作为事务执行。单个API可以调用具有不同读/写属性的多个DAO函数。
执行此任务的最佳方法是什么?
您可以在DAO层中注入两个单独的会话工厂来管理这些事务。或者,您可以使用AbstractRoutingDataSource。在此处
$中查看文章b $ bI 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?
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
这篇关于会话工厂以处理多个数据库连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!