Search code examples
eclipselinkmulti-tenant

Difference between @multitenant(SINGLE_TABLE) and @multitenant(VPD) in EclipseLink


Despite the fact I searched a lot in the internet and read many articles, I still be unable to get the difference between the Single_Table strategy and the VPD strategy of EclipseLink.

At first I thought that the "VPD" is the implementation of the "Separate database strategy" but then I discovered that we use the same table for all tenants in both strategies.

Could anyone clarify the difference between the two strategies please?


Solution

  • The main difference is the level where the filtering is done.

    When using SINGLE_TABLE multitenancy, EclipseLink is responsible for including tenant_id in all generated queries.

    When using VPD, filtering is done on database level. So, EclipseLink will generate SQL queries which don't include tenant_id, and database will take care of the filtering.

    Quote from the documentation

    VPD allows users to identify themselves as a specific user, and will be able to 'see' data specific to that user. All result limiting is done at the database level, removing the need to send special SQL containing an additional comparison.