views:

715

answers:

2

Having in mind that each webapp has its own separate database (but all databases are in the same database server).

The scenario is that I have a multi-tenant saas application - I deploy the same application for each customer. Each customer works on a database that is called db_cid, where cid is the customer id, i.e. a a unique customer identifier.

Working with hibernate.

A: 

Have you thought about configuring a JNDI connection in the tomcat (global) context? It can be a pooled connection, as described in JNDI datasource example.

extraneon
+3  A: 

If you need to share ressources between web application you must let the web container manage them, and put them in JNDI. The web application can then get the resources from a JNDI context very easily.

JDBC connection pools are so typical so every web container documents how to set them up.

For stand-alone programs we use Simple JNDI http://www.osjava.org/simple-jndi/ which provides the external configuration which allows us to separate codebase from configuration completely.

Try it, you'll like it :)

Thorbjørn Ravn Andersen