Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure multiple DataSources for multitenancy in Hibernate

I am trying to add multitenancy to a java application using the separate schema approach as outlined in this webinar

I wanted to know how would I configure multiple data sources via spring perhaps by using properties files and get the data sources from the spring context based on tenant id.

More importantly, though I want to be able to configure my custom connection provider implementation that supports this multitenancy feature to be used by Hibernate instead of the injected ConnectionProvider that it uses by default.

How can i achieve this.

like image 358
Asif Mohammed Avatar asked Jul 24 '11 03:07

Asif Mohammed


People also ask

What is multi-tenancy in hibernate?

Multitenancy allows multiple clients or tenants use a single resource or, in the context of this article, a single database instance. The purpose is to isolate the information each tenant needs from the shared database. In this tutorial, we'll introduce various approaches to configuring multitenancy in Hibernate 5.

What is the purpose of multi-tenancy?

Multitenancy reduces the need for individual users to manage infrastructure and handle updates and maintenance. Individual tenants can rely on a central cloud provider, rather than their own teams, to handle those routine chores.


1 Answers

Use the AbstractRoutingDataSource. See my answer located @ Multiple Entity Manager issue in Spring when using more than one datasource.

like image 94
atrain Avatar answered Oct 04 '22 00:10

atrain