Why @TenantId is not allowed in primary key?

I was trying to use @TenantId in @Embeddable or @IdClass, and it didn’t work .

Failed to initialize JPA EntityManagerFactory: Property 'org.w3worker.academy.api_server.academy_user.models.AcademyUser.key.academy' is annotated 'interface org.hibernate.annotations.TenantId' which is not an '@IdGeneratorType'

I have a very simple requirement, that every user will be unique to tenant. So, i wanted to have a primary key column on (tenant_id,email). But, i can’t have due to hibernate limitation.

Similarly, there can be situations where we want counter to be unique to tenant. For example, consider a could based SaaS website table, where appId in saas app starts from 1 for every tenant. So, we can have primary key on (tenant_id,app_id)

I just wanted to know why hibernate doesn’t allow to have @TenantId in @Embeddable or @IdClass? What benefits do hibernate gains from this decision?

Since a tenant id is implemented through a generator, I think that you are running into a current limitation: Jira