Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

XADAtaSource issue  RSS feed

Razi Abbas
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The situation is that we have two databases that are replicated to provide fail-over in case one of them goes down. But we have to do the fail-over in our code, that is checking the first connection and if it is not working then switching to the second one.
We are retrieving connections in our DAOs which are called by the Sesion and Entity beans. The EJB methods have REQUIRED transaction attribute set.
The problem is that in the DAO method if the first datasource doesn't work for any reason (like incorrect hostname, bad username/password) then the code tries to create connection to the second database and right there it throws an exception that we are using two datasources in one transaction and that makes it global and we should switch to the DataSource implementation that can handle 2-phase committs.
We want to avoid using XADataSources because there is an overhead and we will actually never use transactions that span two data sources. We just need fail-over. One solution that might work is to get a connection in a separate method in the EJBs and mark its transaction boundry as NOT_SUPPORTED. But then this would require us to pass the Connection object to all the DAO methods because the data access logic is there.
Can anyone think of a better way to deal with this issue without switching to XADataSource.
- Razi
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!