Java Persistence API (JPA) Extensions Reference for EclipseLink, Release 2.5
  Go To Table Of Contents
 Search
 PDFComments
Comments


@TenantTableDiscriminator

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

java.lang.String ContextProperty

(Optional) Name of the context property to apply to as tenant table discriminator

eclipselink.tenant-id

TenantTableDiscriminator type

(Optional) Type of tenant table discriminator to use with the tables of the persistence unit.

  • SCHEMA

  • SUFFIX

  • PREFIX

SUFFIX



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:

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