EclipseLink:EntityManager.merge():为什么TENANT_ID没有为UPDATE操作添加运行时?

时间:2014-03-13 17:11:40

标签: eclipselink

我已经完成了EclipseLink单表多租户功能规范。

以下是阅读的一部分,我有点惊讶。

任务4:执行操作和查询

The tenant discriminator column is used at runtime through entity manager operations and querying. The tenant discriminator column and value are supported through the following entity manager operations:

    persist()

    find()

    refresh()

The tenant discriminator column and value are supported through the following queries:

    Named queries

    Update all

    Delete all

为什么TENANT_ID在运行时不用于以下操作。

merge()
delete()

为什么以下操作不需要它?我需要它,因为在更新任何记录时,我需要在UPDATE查询的WHERE子句中附加TENANT_ID。 因为,在单个表多租户中,将有多个租户拥有相同用户的用户,我需要TENANT_ID才能更新特定的租户记录。

请帮助我,因为我只是在merge()操作中被困住。

1 个答案:

答案 0 :(得分:0)

我们遇到了相同的症状,我们的答案是将primaryKey=true添加到租户鉴别器注释中,以指示tenant_id必须作为删除和合并操作中使用的主键的一部分包含在内:

@Multitenant
@TenantDiscriminatorColumn(name = "tenant_id", contextProperty = "tenant_id", primaryKey=true)