Single-schema multi-tenancy with a Hibernate filter is a popular pattern. Every tenant table has a tenant_id column, a @Filter adds tenant_id = :tenantId to every query, and an aspect turns the filter on for each request. Lists, searches and reports are all isolated, and the tests for them pass.
There is one hole in it that is easy to miss, and my own starter kit had it. This is how it works and how version 5.3 closes it in two layers.
The gap described here is fixed in Arab Enterprise Kit 5.3, and the update is free for every v5.x license.
The hole
Spring Data's SimpleJpaRepository.findById calls EntityManager.find . Hibernate filters apply to queries (HQL, JPQL, Criteria and filtered collections). They do not apply to loading an entity by its primary key.
// Looks safe, is not: EntityManager.find ignores the tenant filter Invoice invoice = invoiceRepository . findById ( 42L ).…