How to handle multiple datasources in a web application?

I have a J2EE Web application with Servlets and Java ServerPages. Beside this I have a in-house developed API for certain services built using Hibernate and Spring with POJO's and some EJB.

There are 8 databases which will be used by the web application. I have heard that multiple datasources with Spring is hard to design around. Considering that I have no choice not to use Spring or Hibernate as the API's are using it.

Anyone have a good design spesification for how to handle multiple datasources. The datasource(database) will be chosen by the user in the web application.

[600 byte] By [DJ_Vikinga] at [2007-11-27 7:14:48]
# 1

Let me get this straight. You have a web application that uses spring framework and hibernate to access the database. You want the user to be able to select the database that he wants to access using spring and hibernate.

Hopefully you are using the Spring Framework Hibernate DAO. I know you can have more that one spring application context. You can then trying to load a seperate spring application context for each database. Each application context would have it's own configuration files with the connection parameters for each datasource. You could still use JNDi entries in the web.xml for each datasource.

Then you would need a service locater so that when a user selected a datasource he would get the application context for that datasource which he would use for the rest of his session.

I think it is doable. It means a long load time. And you'll need to keep the application contexts as small as possible to conserve resources.

tolmanka at 2007-7-12 19:05:02 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
define them in context.xml
harrriiiia at 2007-7-12 19:05:02 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...