Hi all,
I would appreciate your PoV on the following issue.
We are about to start developing a web application for a large outsourcing company. The application will be used by users belonging to different companies. Each company has a dedicated schema on the database. The table structure is identical on each schema (so we have the same data model replicated n times on n schemas).
The application must access data selecting at runtime the right schema based on the user's company. If plain jdbc was used, the solution would be straightforward: the SQL code in the statement would contain a parametrized schema based on the company name contained in the session context:
Code:
sqlQuery = "SELECT .... FROM "+companyCode+".table1 where ....";
How would you approach this issue with Hibernate?
My solution is to have n different mapping files (one for each schema), and to istantiate n different net.sf.hibernate.cfg.Configuration objects, putting them in the application context. When a user logs in, so that can be identified as a company user, a pointer to the right Configuration object will be put into the session context. In this way I should be able to address at runtime a specific schema on a user basis.
Do you think that it would work? Are there better solutions?
Thanks for your help.
Regards.
Dario Di Bella