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-
Inside the persistence.xml I added –
<property name="hibernate.current_tenant_identifier_resolver"
value="com.avm.security.TenantIdentifierResolver"/>
I also created this class-
public class TenantIdentifierResolver implements CurrentTenantIdentifierResolver {
@Override
public String resolveCurrentTenantIdentifier() {
return TenantFilter.getTenantIdFromContext();
}
@Override
public boolean validateExistingCurrentSessions() {
return true;
}
}
With this alone I am getting the error – org.hibernate.HibernateException: SessionFactory configured for multi-tenancy, but no tenant identifier specified
Any ideas what I am missing?