Table-per-tenant multitenancy allows multiple tenants of an application to isolate their data in one or more tenant-specific tables. The tenant table discriminator specifies how to discriminate the tenant's tables from the other tenants' tables in a table-per-tenant multitenancy strategy.
Annotation Elements
Table 2-69 describes this annotation's elements.
Table 2-69 @TenantTableDiscriminator Annotation Elements
Annotation Element | Description | Default |
---|---|---|
|
(Optional) Name of the context property to apply to as tenant table discriminator |
|
|
(Optional) Type of tenant table discriminator to use with the tables of the persistence unit.
|
|
Usage
In table-per-tenant multitenancy, tenants' tables can be in the same schema, using a prefix or suffix naming pattern to distinguish them; or they can be in separate schemas. The tenant table discriminator identifies whether to use the prefix or suffix naming pattern or to use a separate schema to identify and isolate the tenant's tables from other tenants' tables. The types are:
Schema: Applies the tenant table discriminator as a schema to all multitenant tables. This strategy requires appropriate database provisioning.
Suffix: Applies the tenant table discriminator as a suffix to all multitenant tables. This is the default strategy.
Prefix: Applies the tenant table discriminator as a prefix to all multitenant tables.
Tenant table discriminator can be specified at the entity or mapped superclass level and must always be used with Multitenant(TABLE_PER_TENANT)
. It is not sufficient to specify only a tenant table discriminator.
For more information about using @TenantTableDiscriminator
and table-per-tenant multitenancy, see "@Multitenant".
Examples
The following example shows a SCHEMA
-type table discriminator.
Example 2-112 Using @TenantTableDiscriminator Annotation
@Entity @Table(name=“EMP”) @Multitenant(TABLE_PER_TENANT) @TenantTableDiscriminator(type=SCHEMA, contextProperty="eclipselink.tenant-id") public class Employee { ... }
Example 2-113 Using <tenant-table-discriminator> XML
<entity class="Employee"> <multitenant type="TABLE_PER_TENANT"> <tenant-table-discriminator type="SCHEMA" context-property="eclipselink.tenant-id"/> </multitenant> <table name="EMP"> ... </entity>
See Also
"Using Multitenancy" in Solutions Guide for EclispeLink
Multitenant Examples at http://wiki.eclipse.org/EclipseLink/Examples/JPA/Multitenant