I want to convert my application to support multi-tenancy using shared tables (i.e. each table receives a tenant ID). Obviously, I can no longer use @Column(unique = true) , because it will provide uniqueness for all tenants, which I do not want.
@Column(unique = true)
I am using Glassfish 3.1.1 with EclipseLink. Is there a way to make @Column(unique = true) uniqueness for each tenant (and not for the table). Or do I need to provide this in business logic?
You can also specify a unique constraint for the @Table annotation, for example.
@Table
@Table(name = "USERS", uniqueConstraints = @UniqueConstraint(columnNames = {"TENANT_ID", "username"}))
EclipseLink supports multi-level use of user annotations ( @Multitenant , @TenantDiscriminatorColumn and @TenantDiscriminatorColumns ) or equivalent attributes in the eclipselink-orm.xml , since version 2.3.0 . More information on how to use this supported feature can be found in the EclipseLink wiki ; A related screencast can be found on Youtube.
@Multitenant
@TenantDiscriminatorColumn
@TenantDiscriminatorColumns
eclipselink-orm.xml
Therefore, I assumed that using the @Unique annotation @Unique completely impossible to do this.
@Unique