Search code examples
javaspring-boothibernateliquibasemulti-tenant

Is MultiTenancyStrategy deprecated in Hibernate 6


I'm trying to implement Multi-tenant application using Spring Boot 3.

Now I need to connect multiple schemas in single database. Also I use LIQUIBASE for manage schema changes

When configure Hibernate entity manager for tenants entity manger factory, I can't configure MULTI_TENANT Strategy type. MultiTenancyStrategy cannot find in hibernate.

Map<String, Object> properties = new HashMap<>(this.jpaProperties.getProperties());
        properties.put(AvailableSettings.PHYSICAL_NAMING_STRATEGY, "org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy");
        properties.put(AvailableSettings.IMPLICIT_NAMING_STRATEGY, "org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy");
        properties.put(AvailableSettings.BEAN_CONTAINER, new SpringBeanContainer(this.beanFactory));
        properties.remove(AvailableSettings.DEFAULT_SCHEMA);
        properties.put(AvailableSettings.MULTI_TENANT, MultiTenancyStrategy.SCHEMA);
        properties.put(AvailableSettings.MULTI_TENANT_CONNECTION_PROVIDER, connectionProvider);
        properties.put(AvailableSettings.MULTI_TENANT_IDENTIFIER_RESOLVER, tenantResolver);
        emfBean.setJpaPropertyMap(properties);

properties.put(AvailableSettings.MULTI_TENANT, MultiTenancyStrategy.SCHEMA);

Please anyone give me a solution for this.


Solution

  • from hibernate 6 migration guide

    Remove any reference to MultiTenancyStrategy from your application: they are no longer necessary. hibernate.multiTenancy will be ignored and AvailableSettings.MULTI_TENANT/MultiTenancyStrategy will lead to compilation errors since they have been removed.