Spring + Hibernate SessionFactory + AbstractRoutingDataSource

前端 未结 1 1498
余生分开走
余生分开走 2021-01-14 04:12

I have an Spring+Hibernate/Flex application that needs to switch dynamically between database schemas. To accomplish that I implemented a AbstractRoutingDataSource following

相关标签:
1条回答
  • 2021-01-14 05:13

    It's clear that selection of a particular DataSource actually happens when AbstractRoutingDataSource.getConnection() is called, i.e. when transaction-bound Hibernate Session is created. In your case it happens when you enter a @Transactional method.

    Thus, you can't switch schemes inside a transaction. You have to execute separate transactions against different schemes. To execute several transactions inside the same method you can use programmatic transaction management (TransactionTemplate) instead of @Transactional.

    0 讨论(0)
提交回复
热议问题