Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Switching data sources based on environment variable in JPA

 
Akshay Lele
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I am using Open JPA and Websphere server.

I am trying to develop a code in JPA that can switch between 2 data sources. It would be some thing like this, where useOracleDS is the environemnt variable:

if (useOracleDS){
Call method setPersistenceUnitName("oracle") on object of LocalContainerEntityManagerFactoryBean.
}
else{
Call method setPersistenceUnitName("informix") on object of LocalContainerEntityManagerFactoryBean.
}

Some extra info, the two data sources are for production(informix) and DR(oracle) hence they have the same table names etc.

My question is this option correct or there are other good options in JPA for do the switching between 2 data sources.

I have just started using JPA so any help on this would be greatly appreciated.

Thanks a lot.
 
Vijitha Kumara
Bartender
Posts: 3913
9
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
DR(oracle) hence they

What is DR?

If you set the persistence unit properly at the application startup before the provider get initialized then I don't think it would be a problem.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic