如何在多租户环境中使用JPA @Column(unique = true)?
我想将我的应用程序转换为支持使用共享表的多租户(即每个表都有一个租户 ID)。显然,我将无法再使用 @Column(unique = true)
,因为它会强制所有租户的唯一性,这是我不希望的。
我正在使用 Glassfish 3.1.1 和 EclipseLink。有没有办法让 @Column(unique = true)
强制每个租户(而不是每个表)具有唯一性。或者我必须在业务逻辑中强制执行此操作?
I want to convert my application to support multi-tenancy using shared tables (i.e. every table gets a tenant id). Obviously, I would not be able to use @Column(unique = true)
any more, because it would enforce uniqueness across all tenants, which I don't want.
I'm using Glassfish 3.1.1 with EclipseLink. Is there a way make @Column(unique = true)
force uniqueness per tenant (rather than per table). Or do I have to enforce this in the business logic?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
还可以在 @Table 注释上指定唯一性约束,例如
It is also possible to specify uniqueness constraint on then
@Table
annotation, e.g.EclipseLink 使用自定义注释(
@Multitenant
、@TenantDiscriminatorColumn
和@TenantDiscriminatorColumns
)或 eclipselink-orm 中的等效属性支持多租户.xml 文件,自 版本起2.3.0。有关如何使用此支持的功能的更多信息,请访问 EclipseLink wiki ;您可以在 YouTube 上找到相关截屏视频。因此,我认为单独使用
@Unique
注释是完全不可能的。EclipseLink supports multi-tenancy using custom annotations (
@Multitenant
,@TenantDiscriminatorColumn
and@TenantDiscriminatorColumns
) or the equivalent attributes ineclipselink-orm.xml
file, since version 2.3.0. More information on how to use this supported feature is available in the EclipseLink wiki; an associated screencast can be found on Youtube.I would therefore assume that it is quite impossible to do so with the
@Unique
annotation alone.