I have an application that is designed in such a way that 1 applicaion server uses multiple databases (each with the same schema). The database used is dependent on the user logged into the application. I need to implement hibernate and spring in this application.
As i see it different multiple DB's means multiple hibernate session factories. Thats fine, the problem is that the HibernateTempate, HibernateTransactionManager and my DAO's need to use different hibernate session factories depending on the user and so the session factory used needs to be determined in runtime rather than configures statically in spring config.
Possible solutions i have come up with are:
1) Inject a session factory proxy into classes that use the hibernate session factory instead of a session factory itself.
2) Extend classes that use hibernate session factory overriding getSessionFactory() methods.
Has anybody encountered this "special case" or got any suggestions about the bets way to resolve this?


Reply With Quote
