简体   繁体   中英

Multi-Tenant with shared database and discriminator column

Hibernate Multi-tenant Shared Database (discriminator column) until now still not implemented.

I'm working on a Quarkus RestEasy JAX-RS endpoint. I want to use a Multi-Tenant Architecture (not separate database or separate schema but shared database with discriminator column like tenantId). Quarkus also only support separate database and separate schema like Hibernate.

So, how can I implement a custom resolver to write my endpoint resources methods (get, post, put, delete) according to a tenantId?

I thought about an interceptor or filter, but I have no idea how to implement it with Quarkus.

The idea is (SaaS):

  • Create customer account (set him a tenant ID)
  • When a user login, data are fetched according to his tenantId.

The use case:

Tenant1 sends HTTP request containing his tenantId, from endpoint resources, get the tenantId and implement save(), getAll(), get(), delete() methods according to the current tenantId value, and so every tenant will only get or add his own data.

Other possibility:

Is it possible to use a separate schema and write a service (manager dashboard) which can pickup data from all tenants schemas?

Example:

  • Tenant1 = StackOverflow US (number of employees = 50) (employee table in SCHEMA 1)

  • Tenant2 = StackOverflow France (number of employees = 30) (employee table in SCHEMA 2)

  • StackOverFlow Global Manager Dashboard (Total employees = 80, sum of Schema 1 employee table and Schema 2 employee table ) and he can also have statistics by subsidiary.

Quarkus currently only support separate database and separate schema for multi-tenancy, see https://quarkus.io/guides/hibernate-orm#multitenancy

What you want is Partitioned (discriminator) data, see https://docs.jboss.org/hibernate/orm/4.3/devguide/en-US/html/ch16.html#d5e4808

So, if you can use separate schema, it's doable OOTB with Quarkus.

For your global dashboard, you can for example create a view on a dedicated schema that is the union of the corresponding table on "by tenant" schema.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM