EclipseLink : EntityManager.merge() : Why TENANT_I

2019-08-05 05:02发布

问题:

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.

回答1:

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