Hibernate / EclipseLink Interview questions
How do you implement multitenancy in EclipseLink?
EclipseLink supports multitenancy natively through the @Multitenant annotation, which lets multiple tenants' data coexist while keeping each tenant's queries automatically scoped to only their own rows.
@Entity @Multitenant(MultitenantType.SINGLE_TABLE) @TenantDiscriminatorColumn(name = "TENANT_ID", contextProperty = "tenant.id") public class Invoice { @Id private Long id; private BigDecimal amount; }
The most common strategy, SINGLE_TABLE, stores all tenants in one shared table with a discriminator column, and EclipseLink automatically appends the tenant filter to every query based on a context property (like tenant.id) supplied when the EntityManager is created. Other strategies include TABLE_PER_TENANT, where each tenant gets a physically separate table, and, for Oracle databases specifically, integration with Virtual Private Database (VPD) to enforce tenant isolation at the database layer itself.
Because the tenant context is tied to the property supplied at EntityManager creation, mixing tenant data within a single persistence context isn't possible by design, which is exactly the safety property multitenancy support is meant to guarantee.
More Related questions...