0

I don't expect you have much experience with this approach.

I have an app working with tenants. For some tenants each have his own db(db per tenant), but for others it's 'default' db with tenantId as discriminator column. I currently implemented @TenantId over these values in entities alongside TenantIdentifierResolver. I also fetch the Tenant from the header and set the context with it.

Everything works, I have Tenant check on production so it will never be null, but for other purposes it's much more comfortable to just disable this filter if it's not given.

The question is how to get the let's say global context in which case the tenant is null and I want to disable the multitenancy discriminator for each http request that fulfills the null tenant principle.

Any ideas?

I already tried with filters @Filter and AOP approach, but that didn't went well as I would have to implement a whole lot of EntityManager and Factories and Connection Management stuff, which for some extent I did, but didn't want to dive deep into that as I would need to refactor the whole app just to do it - or so I thought.

Example code: Having

@FilterDef(name = "tenantFilter", parameters = {@ParamDef(name = "tenantId", type = String.class)}) @Filter(name = "tenantFilter", condition = "tenant_id = :tenantId") class SomeEntity{}

@Around("execution (* org.hibernate.SessionFactory+ .openSession())")

How to weave at compile time into org.hibernate? It doesnt seem to be working when include in pom this org.hibernate hibernate-core etc.

Majks
  • 1
  • 1

0 Answers0