Skip to content

Sample Project with Micronaut 2.0 JPA Hibernate multi tenant by database

Notifications You must be signed in to change notification settings

tqad/micronaut-data-jpa-multi-tenant

Repository files navigation

Micronaut - Multi Tenancy by Database

This sample project shows how to use micronaut and hibernate with multi-tenancy on database level.

Included:

Update for Micronaut 3.6.1

The solution

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 by JpaConfigurationCreatedEventListener)

MultiTenantResolver

Custom implementation of Hibernate CurrentTenantIdentifierResolver. Determine the current tenant by using Micronaut-TenantResolver.

MultiTenantConnectionProvider

Custom implementation of Hibernate AbstractDataSourceBasedMultiTenantConnectionProviderImpl. Provide the tenant related DataSource by utilizing the Micronaut BeanProvider<DataSource> and DataSourceResolver.

JpaConfigurationCreatedEventListener

Programmatic approach to configure the default JpaConfiguration to set the multi tenancy parameter for Hibernate.

MultiTenantDataEntityManagerFactoryBean

removed - no longer needed

About

Sample Project with Micronaut 2.0 JPA Hibernate multi tenant by database

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages