• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

XADAtaSource issue

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
Thanks,
- Razi
 
And inside of my fortune cookie was this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic