2

We have a struts-hibernate-mysql application running on tomcat. We want to have the same codebase for the application but would like to have the application connect to different databases dynamically based on the user who logs in into the system.

Basically we would like to have different databases for each different school. The database for each school would be big hence we have decided to have database for each school separate but the Java code base to be same. Hence we would not like to have multiple instances of the Web application deployed on tomcat but a single application should be able to connect to various databases depending on the person who logins.

How can this be achieved?

Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
Kalpak
  • 3,510
  • 4
  • 22
  • 21

1 Answers1

0

A better designed domain model would be the best approach.

Otherwise I'd create multiple data sources (using pools of course) and have multiple hibernate session factories (or entity managers depending on your version of hibernate).

You can keep a map that has the key for a school mapped to its session factory. When you execcute your code get the correct factory for the school.

ramsinb
  • 1,985
  • 12
  • 17