There is no @MultiTenant annotation in the JPA specification. Multi-tenancy is a provider feature: Hibernate offers @TenantId for discriminator-based tenancy plus schema and database strategies, and EclipseLink has its own @Multitenant annotation (note the lowercase t). If you see @MultiTenant in a tutorial, it is either custom code or a confusion with one of these.
Multi-tenancy means one application instance serves several customers (tenants) while keeping their data isolated. Which approach you pick decides how the isolation is implemented and how much it costs to operate.
No. Jakarta Persistence (the current name of JPA) has no multi-tenancy annotation or API. Entities such as @Entity, @Table and @Column are standard, but tenant handling is delegated to the persistence provider. Because of that, code that depends on tenancy is not portable between Hibernate and EclipseLink.
Some projects define their own @MultiTenant marker annotation and read it with an aspect, a Spring Data repository base class or a Hibernate interceptor. That is legitimate, but it is custom behaviour that you must write and test yourself.
| Strategy | Isolation | Cost | Typical use |
|---|---|---|---|
| Separate database per tenant | Strongest | Highest, many connection pools and migrations | Few large or regulated tenants |
| Separate schema per tenant | Strong | Medium, one migration run per schema | Dozens to hundreds of tenants |
| Shared schema with a discriminator column | Weakest at the database level | Lowest | Many small tenants |
For PostgreSQL, a shared schema can be hardened with row-level security so that the database also enforces the tenant filter, not only your application code.
Since Hibernate 6.0 you can mark a column as the tenant identifier with org.hibernate.annotations.TenantId. Hibernate then adds the tenant to inserts and to the WHERE clause of queries and loads for that entity:
You then tell Hibernate which tenant is current by implementing CurrentTenantIdentifierResolver:
TenantContext is your own holder, usually a ThreadLocal that a servlet filter sets from the request host name, a header or the authenticated user's token claim. Always clear it at the end of the request. With virtual threads or async code, prefer a scoped value or pass the tenant explicitly rather than relying on thread identity alone.
In Spring Boot, register the resolver by exposing it as a bean or setting the property:
For separate schemas or databases, Hibernate needs a MultiTenantConnectionProvider that returns a connection for the current tenant, for example by running SET search_path or choosing a different DataSource:
Validate the tenant identifier against a known list before using it as a schema name, otherwise a crafted value can reach SQL.
EclipseLink ships @Multitenant with types such as single-table, table-per-tenant and virtual private database. It is configured with @TenantDiscriminatorColumn and a persistence-unit property for the tenant value. Use it only if EclipseLink is your provider.
(tenant_id, email).No. Hibernate uses @TenantId and the resolver and connection provider interfaces. A class named @MultiTenant only exists if your project or a library defines it.
A shared schema with @TenantId is the simplest and cheapest, schema per tenant is a good middle ground, and a database per tenant gives the strongest isolation. Choose by tenant count, compliance needs and operational budget.
Read it in a filter or interceptor from the host name, header or JWT, store it in a request-scoped holder, and return it from CurrentTenantIdentifierResolver.
Yes. Spring Data repositories use the same EntityManager, so Hibernate applies the tenant filter automatically once the resolver is configured.
JPA has no @MultiTenant annotation. Use Hibernate's @TenantId for shared-schema tenancy, or a MultiTenantConnectionProvider for schema or database isolation, and set the tenant per request through CurrentTenantIdentifierResolver. Test isolation explicitly, including native queries, caches and background jobs.