Skip to main content

multiple datasources

4 replies [Last post]
priyasubu
Offline
Joined: 2007-08-21

Hi
I am stuck in a bit of dilemma any help would be great
The thing is my application server will need to speek to 3 different datasources so if there is a request say for something that is say related to say asian subcontinent I would try to do a jndi lookup for that datasource and use it and if there is something related to european i would use another ds
now int he dao if I were using i inject the datasource using

@PersistenceContext(unitName = "abc")
private EntityManager entityManager;
adn I configure this in my persistence.xml how would I do this for multiple datasources?
Cheers
priya

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
mvatkina
Offline
Joined: 2005-04-04

It is not possible with TopLink Essentials (default in GlassFish) to dynamically change the datasource for the same PU name. But if you have only 3 predefined datasources, define 3 PUs in the same persistence.xml, and inject 3 different entity managers. Then choose which one to use depending on the incoming information.

Regards,
-marina

samdoyle
Offline
Joined: 2006-12-27

How do you pick your PU if you have multiple ones injected?

S.D.

mvatkina
Offline
Joined: 2005-04-04

How would you know to which database you want to connect?

thanks,
-marina

priyasubu
Offline
Joined: 2007-08-21

well say depending on country I know the country and using the country I know which datasource ....
I am using hibernate.I am thinking of having some kind of service locator to find the datasource given region(so need a map or something for this) and then get the entitymanager for that datasource and use that don't know how exactly any ideas.....
Cheers
Priya