This is a very simple (and naive ? :) ) way to kickstart the usage of the Hibernate multi
tenancy feature.
- Add this artifact to your project
- Extend the class com.twimba.hibernate.AbstractMultiTenantConnectionProvider
- Implement a org.hibernate.context.spi.CurrentTenantIdentifierResolver
- Configure hibernate to use multi tenancy:
params.put(Environment.MULTI_TENANT, MultiTenancyStrategy.DATABASE.name());
params.put(Environment.MULTI_TENANT_CONNECTION_PROVIDER, <a sub class of AbstractMultiTenantConnectionProvider>);
params.put(Environment.MULTI_TENANT_IDENTIFIER_RESOLVER, <an implementation of the CurrentTenantIdentifierResolver> );
- Add tenants configuration.
- Done! :)
There is a sample implementation in here
This is available in the Apache Licence 2.0 http://www.tldrlegal.com/license/apache-license-2.0-(apache-2.0)