• Post Reply Bookmark Topic Watch Topic
  • New Topic

Switching data sources based on environment variable in JPA  RSS feed

 
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.
 
Bartender
Posts: 4013
42
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
Boost this thread!