EclipseLink 中@multitenant(SINGLE_TABLE) 和@multitenant(VPD) 的区别

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

尽管我在网上搜索了很多,也看了很多文章,但我仍然无法理解 Single_Table 策略和 [= EclipseLink 的 17=]VPD 策略。

一开始我以为"VPD"是“分库策略”的实现,后来发现我们用的是一样的table对于两种策略中的所有租户。

谁能解释一下这两种策略之间的区别?

主要区别在于完成过滤的级别。

使用 SINGLE_TABLE 多租户时,EclipseLink 负责在所有生成的查询中包含 tenant_id

使用 VPD 时,过滤是在数据库级别完成的。因此,EclipseLink 将生成 SQL 个不包含 tenant_id 的查询,数据库将负责过滤。

引自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.