File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "XADAtaSource issue" Watch "XADAtaSource issue" New topic
Author

XADAtaSource issue

Razi Abbas
Greenhorn

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.
Thanks,
- Razi
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: XADAtaSource issue