Meaningless Drivel is fun!
The moose likes EJB and other Java EE Technologies and the fly likes XADAtaSource issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "XADAtaSource issue" Watch "XADAtaSource issue" New topic

XADAtaSource issue

Razi Abbas

Joined: Apr 30, 2002
Posts: 9
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
I agree. Here's the link:
subject: XADAtaSource issue
It's not a secret anymore!