Example of multitenant usage - hibernate 4 & spring 3
Multitenant support offer to have multiple DBs or Schemas for "tenants". It is transparent from application point of view.
- hibernate.multiTenancy
- DATABASE
- SCHEMA
- DISCRIMINATOR - it is planned for Hibernate 5
-
hibernate.tenant_identifier_resolver - it must return tenant id for current thread. Typically from request header?
-
hibernate.multi_tenant_connection_provider - it must return connection for given tenant indentifier (result of hibernate.tenant_identifier_resolver)
-
sessionFactory
-
hibernateProperties
-
- it can be set using map, so you can set bean for some hibernate properties (e.g. hibernate.tenant_identifier_resolver)
-
- hibernate.hbm2ddl.auto cannot be used or it will fail
-
webSessionTenantIdentifierResolver
-
there is scope set to request so every http request to server will create new instance of this class but
-
you have to use
<aop:scoped-proxy/>
to let spring create a proxy around this bean in order to provide new instance every time
- for request scoped bean you can use
@Autowired
private HttpServletRequest request;