如何在多租户环境中使用JPA @Column(unique = true)?

发布于 2024-11-25 13:31:51 字数 244 浏览 3 评论 0原文

我想将我的应用程序转换为支持使用共享表的多租户(即每个表都有一个租户 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

素罗衫 2024-12-02 13:31:51

还可以在 @Table 注释上指定唯一性约束,例如

@Table(name = "USERS", uniqueConstraints = @UniqueConstraint(columnNames = {"TENANT_ID", "username"}))

It is also possible to specify uniqueness constraint on then @Tableannotation, e.g.

@Table(name = "USERS", uniqueConstraints = @UniqueConstraint(columnNames = {"TENANT_ID", "username"}))
缱绻入梦 2024-12-02 13:31:51

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 in eclipselink-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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文