views:

19

answers:

1

I have an entity bean that will represent an expected result over multiple databases/datasources and can also be different queries executed, but same result always comming back. So the bean is re-used over different datasources that should be able to be dynamicly selected.

Is it possible with JPA to select during runtime the data source to be used to execute a query, and return the same type of entity bean? Also, does my ejb/application need to define the datasources that will be used? Or can I always specify via jndi what datasource to use? Modifying the descriptor's and re-deploying an application everytime a new datasource is created is not an option.

Sorry if the question does not make 100% sense, rather difficult to get the idea through.

+1  A: 

Is it possible with JPA to select during runtime the data source to be used to execute a query, and return the same type of entity bean?

You can't change the datasource of a persistence unit at runtime. However, you can configure several persistence unit and use one or another EntityManagerFactory. Maybe JPA is not the right tool for your use case.

Modifying the descriptor's and re-deploying an application everytime a new datasource is created is not an option.

And how will the application be aware of the "available datasources"?

Pascal Thivent
Thank you, you are right, JPA will not be the right tool here. I was hoping that's not the case.With the second question I meant that the j2ee container would have all the datasources configured, but the application itself would not. But that wont matter much if I move away from JPA. Thank you.