How do I get Hibernate @TenantId to work with @JoinColumn
In my application I have switched to a multi-tenant database. I am using Java 21 with hibernate 6.5.2, and using @TenantId to discriminate between clients (Not using Spring). Same database, same schema, different tenant_id column on every table. After making the switch all the entities on my backend now have a tenant_id string with the @TenantId annotation. Hibernate sees the @TenantId annotation and automatically filters it, persisting objects and fetching objects that have the matching tenantId supplied to hibernate. However, this isn’t working well when using @JoinColumn.
How can I set up a non-Spring multi-tenant database using hibernates @TenantId annotation
I have an application that I am trying to switch from a single tenant to a multi-tenant database. I am using hibernate-core 6.5.2 dependency in my pom file. This backend was not set up using spring and has been updated to use Java 21, Tomcat 10, a newer hibernate, etc. FYI I don’t have experience with multi-tenancy. I am not wanting to do a different database per tenant or different schemas per tenant. I want to use the @TenantId annotation provided by hibernate and combine that with a tenant_id column on every table of the database to discriminate between clients. For the purpose of this question please assume I have all of the database tables updated with tenant_id, all of the entities updated to include a tenant_id column and the @TenantId annotation, and I am able to get the tenant_id from security context and store it in a static final ThreadLocal string. So far I have been working from examples online and have not done much-