This sample project shows how to use micronaut and hibernate with multi-tenancy on database level.
Included:
- Micronaut
- Micronaut Hibernate JPA documentation
- Micronaut Hikari JDBC Connection Pool documentation
- Micronaut Micronaut HTTP Client documentation
- Micronaut Liquibase Database Migration documentation
- https://www.liquibase.org/
- https://www.testcontainers.org/
I'm just using the default steps to enable multi-tenancy with hibernate except that I was forced to use a programmatic approach to configure the default jpa configuration.
Configuration in application.yml:
Datasource
Configuration for every tenant- Default
JpaConfiguration
to define which entity packages should be scanned (multi tenancy configuration is done byJpaConfigurationCreatedEventListener
)
Custom implementation of Hibernate CurrentTenantIdentifierResolver
.
Determine the current tenant by using Micronaut-TenantResolver.
Custom implementation of Hibernate AbstractDataSourceBasedMultiTenantConnectionProviderImpl
.
Provide the tenant related DataSource
by utilizing the Micronaut BeanProvider<DataSource>
and DataSourceResolver
.
Programmatic approach to configure the default JpaConfiguration
to set the multi tenancy parameter for Hibernate.
removed - no longer needed