EclipseLink : EntityManager.merge() : Why TENANT_ID not added runtime for UPDATE operation?

。_饼干妹妹 提交于 2019-12-11 11:42:27

问题


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)


来源:https://stackoverflow.com/questions/22385976/eclipselink-entitymanager-merge-why-tenant-id-not-added-runtime-for-update

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!