Session factories to handle multiple DB connection

2019-05-26 07:36发布

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?

1条回答
戒情不戒烟
2楼-- · 2019-05-26 08:19

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

查看更多
登录 后发表回答