I am trying to implement a multi-level discriminator implementation using Spring Boot and Spring Data.
I created an abstract class to represent an object with several tenants. Something like this:
@MappedSuperclass @FilterDefs({@FilterDef(name = "multi-tenant", parameters = {@ParamDef(name = "tenant", type = "string")})}) @Filter(name = "multi-tenant", condition = "tenant = :tenant") public abstract class MultiTenantEntity extends GenericEntity { @Transient private transient String savedTenant; @PostLoad private void onLoad() throws Exception { this.savedTenant = this.tenant; onEntityModification(); } @PrePersist private void onPersist() { if (getId() == null || getId().equals(0l)) { tenant = SecurityUtil.getCurrentTenant(); } } @PreUpdate @PreRemove private void onEntityModification() throws Exception { String currentTenant = SecurityUtil.getCurrentTenant(); if (!currentTenant.equals(tenant) || !savedTenant.equals(tenant)) { throw new Exception(); } } @NotNull private String tenant; public String getTenant() { return tenant; } }
How to enable global sleep filter with multiple tenants globally?
java spring-boot spring-data spring-data-jpa hibernate
Daniel Gomes
source share