Session factories to handle multiple DB connections

牧云@^-^@ 提交于 2019-12-22 18:29:18

问题


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:


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



来源:https://stackoverflow.com/questions/8723037/session-factories-to-handle-multiple-db-connections

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!