EclipseLink : EntityManager.merge() : Why TENANT_I

2019-08-05 05:03发布

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

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

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

Why TENANT_ID is not used at runtime for below operations.

merge()
delete()

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.

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

标签: eclipselink
1条回答
不美不萌又怎样
2楼-- · 2019-08-05 05:22

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)
查看更多
登录 后发表回答