wood burning stoves 2.0*
The moose likes Object Relational Mapping and the fly likes Switching data sources based on environment variable in JPA Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Switching data sources based on environment variable in JPA" Watch "Switching data sources based on environment variable in JPA" New topic
Author

Switching data sources based on environment variable in JPA

Akshay Lele
Greenhorn

Joined: Apr 06, 2009
Posts: 10
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

Joined: Mar 24, 2008
Posts: 3817

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.


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
 
wood burning stoves
 
subject: Switching data sources based on environment variable in JPA
 
Similar Threads
Technology related question
caching master tables static data
JPA/Hibernate best practices?
OO design for Java Database
Referential integrity error in Child table even when Parent table has values