- Java 17+ Support: Added support for Java 17+ by abstracting away all usages
of
javax.persistence. This is to ensure that the library is compatible with the latest Java versions.- This is a minor change and should not affect any existing implementations.
- HOTFIX: Replaced the use of native entity manager factory
from
LocalContainerEntityManagerFactoryBeanwithEntityManagerFactorySpring Proxy bean while creatingPlatformTransactionManagerbean to ensure that Transactional and Flush behaviour works as expected across all data sources.- This will not lead to any changes in your implementation layer. This is a fix in the generated configuration layer.
- Some minor documentation improvement for dealing with hibernate properties with multiple spring data sources.
-
BREAKING CHANGE: Exact entity packages are now mandatory for each data source. This is to ensure that only the required entities are scanned for each data source and no unnecessary entities are scanned. This is a breaking change as the previous versions took the entity packages from the
@EnableMultiDataSourceConfigannotation, not from the@DataSourceConfigannotation.Before:
@Configuration @EnableMultiDataSourceConfig( repositoryPackages = { "com.sample" }, exactEntityPackages = { "com.sample.project.sample_service.entities.mysql" }, primaryDataSourceConfig = @DataSourceConfig(dataSourceName = "master"), secondaryDataSourceConfigs = { @DataSourceConfig(dataSourceName = "replica-2"), @DataSourceConfig(dataSourceName = "read-replica") } ) public class ServiceConfig { }
After:
@Configuration @EnableMultiDataSourceConfig( repositoryPackages = { "com.sample" }, primaryDataSourceConfig = @DataSourceConfig( dataSourceName = "master", exactEntityPackages = { "com.sample.project.sample_service.entities.mysql", // Assuming master wants access to read entities as well. If not, above package is fine "com.sample.project.sample_service.read_entities.mysql", "com.sample.project.sample_service.read_entities_v2.mysql" } ), secondaryDataSourceConfigs = { @DataSourceConfig( dataSourceName = "read-replica", exactEntityPackages = "com.sample.project.sample_service.read_entities.mysql" ), @DataSourceConfig( dataSourceName = "replica-2", exactEntityPackages = { "com.sample.project.sample_service.read_entities.mysql", // Assuming replica-2 wants access to read entities as well as read entities v2 "com.sample.project.sample_service.read_entities_v2.mysql" } ), } ) public class ServiceConfig { }
-
MULTI-MODULE SUPPORT | BREAKING CHANGE:
@EnableMultiDataSourceConfig.generatedRepositoryPackagePrefixhas been removed. Instead, the generated repository package will be the package of the source repository followed by.generated.repositoriesand then the snake-cased datasource name. This allows this project to finally support Multi-Module projects as the generated repositories will be in the same module as the source repository, instead of being dictated by thegeneratedRepositoryPackagePrefix. -
MULTI MODULE SUPPORT: The inclusion and exclusion filters of the
@EnableJpaRepositoriesannotations generated now internally useFilter.ASSIGNABLE_TYPEandFilter.REGEXso that repository scanning can be smarter across multiple modules. -
Provided dependency of
com.google.auto.service:auto-servicehas been upgraded to1.1.1to avoid CVE-2023-2976 and CVE-2020-8908 vulnerabilities. -
Some minor null-safety improvements and code cleanup.
-
BREAKING CHANGE: Better organised DataSourceConfig to segregate Primary and Secondary data sources as per Spring Convention. Also renamed
@TargetDataSourceto@TargetSecondaryDataSourceto avoid confusion.Before:
@Configuration @EnableMultiDataSourceConfig( repositoryPackages = { "com.sample" }, exactEntityPackages = { "com.sample.project.sample_service.entities.mysql" }, dataSourceConfigs = { @DataSourceConfig(dataSourceName = "master", isPrimary = true), @DataSourceConfig(dataSourceName = "replica-2"), @DataSourceConfig(dataSourceName = "read-replica") } ) public class ServiceConfig { }
After:
@Configuration @EnableMultiDataSourceConfig( repositoryPackages = { "com.sample" }, exactEntityPackages = { "com.sample.project.sample_service.entities.mysql" }, primaryDataSourceConfig = @DataSourceConfig(dataSourceName = "master"), secondaryDataSourceConfigs = { @DataSourceConfig(dataSourceName = "replica-2"), @DataSourceConfig(dataSourceName = "read-replica") } ) public class ServiceConfig { }
-
Allow
@TargetSecondaryDataSourceto be placed on any Repository, not just JpaRepository. -
Adaptive
EntityManagerFactoryforTransactionManagerwill be generated based onLocalContainerEntityManagerFactoryBean. Decoupled from Javax/Jakarta implementations. -
Allow possibility for overriding different JPA properties for each data source by adding
@DataSourceConfig.overridingJpaPropertiesPathfield. By default, it will take the defaultspring.jpa.propertiespath.
- HOTFIX: Fix
@EnableJpaRepositories.basePackagesbeing empty for secondary data sources when@EnableMultiDataSourceConfig.generatedRepositoryPackagePrefixis not set. Instead, it will be set to the package of the@EnableMultiDataSourceConfigannotated class followed by.generated.repositoriesand then the snake-cased datasource name. - Default
@EnableMultiDataSourceConfig.generatedConfigPackagechanged to the package of the@EnableMultiDataSourceConfigannotated class followed by.generated.configinstead of@EnableMultiDataSourceConfig.generatedRepositoryPackagePrefixfollowed by.config. - No repositories will be scanned for data sources which do not have a
@TargetDataSource. - Refactor internal logic for more readability.
- BREAKING CHANGE: Configs must be defined for each data source now
under
@EnableMultiDataSourceConfig.@DataSourceConfig. - BREAKING CHANGE:
@MultiDataSourceRepositoryhas been renamed to@TargetDataSourcefor easier understanding. - Incremented version of Junit and Mockito.
- Restructured DataSource Level configuration for more readability and utility.
- Cosmetic improvements to generated code to include comment explaining hibernate bean container injection reasoning
- Turned utils into singleton classes instead of static classes, and enforced them with Unit Tests.
- Improved documentation
- Unit Tests added for most major elements.
- Had to use reflection for unit tests of generated Repository classes. It could be better.
- Made generated config classes abstract-able by introducing
IMultiDataSourceConfiginterface. - Some internal method name changes for consistency.
- Excluded SLF4J, even as a provided dependency, as it is not required.
- Fixed Sonatype Issues:
- Made Error Messages final static constants in a separate
class:
io.github.dhi13man.spring.datasource.constants.MultiDataSourceErrorConstants. - Changed name of certain classes by adding
MultiDataSourceprefix to avoid name clashes in client code.
- Remove hardcoded DataSource type, and relevant legacy code for increased application-properties-based flexibility with DataSource type.
- Improvements to default code generation package config.
- Proper
isMethodSignatureMatchingcheck while overriding and throwing unsupported exception in base Repository methods to ensure only overriden, annotated methods are supported. - Fix Dependabot Issue #1
- Initial Release with full working implementation of @EnableMultiDataSourceConfig and @MultiDataSourceRepository
- with relevant config.
- Setup for Central Maven Repository Deployment with changed group ID and packages.
- Documentation and Guidelines.