EclipseLink:EntityManager.merge():为什么TENANT_ID没有为UPDATE操作添加运行时? [英] EclipseLink : EntityManager.merge() : Why TENANT_ID not added runtime for UPDATE operation?

查看:92
本文介绍了EclipseLink:EntityManager.merge():为什么TENANT_ID没有为UPDATE操作添加运行时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经通过了EclipseLink单表多租户功能规范。

I have gone through EclipseLink Single Table Multi-Tenancy feature spec.

下面是阅读部分,我有点惊讶。

BELOW is some portion by reading, I am little bit surprised.

任务4:执行操作和查询

Task 4: Perform Operations and Queries

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用于以下操作。

Why TENANT_ID is not used at runtime for below operations.

merge()
delete()

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

Why It is not needed for below operations? I need it because when updating any record , I need to append TENANT_ID in WHERE clause of UPDATE query. Because, In a single table multi-tenancy, there will be users with same user for more than one tenant and I need TENANT_ID to update only specific tenant record.

请帮助我,因为我只限于merge()操作。

Please help me in this, as I am stuck only in merge() operation.

推荐答案

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

We had the same symptoms and the answer for us was to add primaryKey=true to the tenant discriminator annotation to indicate that the tenant_id must be included as a part of the primary key used in delete and merge operations:

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

这篇关于EclipseLink:EntityManager.merge():为什么TENANT_ID没有为UPDATE操作添加运行时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆