I want to implement DISCRIMINATOR based Multi-Tenancy solution for Shared Schema Based Multi-Tenancy Model-common database schema for all tenants.
Technology stack
My questions are
Unlike the separate database and separate schema approaches, which require distinct database connections for each tenant, Hibernate’s tenant discriminator model stores tenant data in a single database and partitions records with a simple column value. We will add a column called tenant_id in all the tables.
As mentioned in the official Hibernate User Guide, there are three approaches to multitenancy in Hibernate: Separate Schema – one schema per tenant in the same physical database instance Partitioned (Discriminator) Data – the data for each tenant is partitioned by a discriminator value
The class is defined with standard JPA and Hibernate annotations. Notably, the @FilterDef and @Filter annotations will allow us to inject a tenant discriminator clause to every SQL query generated for this entity. We will use AspectJ advice, which will set the Filter value.
However, for JPQL query such as this one: Hibernate generates a SQL query which filters by the associated discriminator column (e.g. DTYPE by default): So, because we are filtering by the discriminator column, we might want to index it or include it to speed up queries.
Using hibernate filters you can achieve below items in our application,
In our application we applied this and got great results and applied the same stuff to other web based products as well. For your reference go through the below link and you will get some idea on the above stuffs. http://www.jroller.com/RickHigh/entry/using_spring_aop_and_hibernate
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With