I am looking around for a multitenancy solution for my web application.
I would like to implement a application with Separate Schema Model. I am thinking to have a datasource per session. In order to do that i put datasource and entitymanger in session scope , but thats not working. I am thinking to load data-access-context.xml(which include datasource and other repository beans) file when the user entered username and password and tenantId. I would like to know if it is a good solution?
I am looking around for a multitenancy solution for my web application. I would
Share
Multitenancy is a bit tricky subject and it has to be handled on the JPA provider side so that from the client code perspective nothing or almost nothing changes. eclipselink has support for multitenancy (see: EclipseLink/Development/Indigo/Multi-Tenancy), hibernate just added it recently.
Another approach is to use
AbstractRoutingDataSource, see: Multi tenancy in Hibernate.Using session-scope is way too risky (also you will end up with thousands of database connections, few for every session/user. Finally
EntityManagerand underlying database connections are not serializable so you cannot migrate your session and scale your app properly.