- 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
LocalContainerEntityManagerFactoryBean
withEntityManagerFactory
Spring Proxy bean while creatingPlatformTransactionManager
bean 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
@EnableMultiDataSourceConfig
annotation, not from the@DataSourceConfig
annotation.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.generatedRepositoryPackagePrefix
has been removed. Instead, the generated repository package will be the package of the source repository followed by.generated.repositories
and 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
@EnableJpaRepositories
annotations generated now internally useFilter.ASSIGNABLE_TYPE
andFilter.REGEX
so that repository scanning can be smarter across multiple modules. -
Provided dependency of
com.google.auto.service:auto-service
has been upgraded to1.1.1
to 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
@TargetDataSource
to@TargetSecondaryDataSource
to 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
@TargetSecondaryDataSource
to be placed on any Repository, not just JpaRepository. -
Adaptive
EntityManagerFactory
forTransactionManager
will be generated based onLocalContainerEntityManagerFactoryBean
. Decoupled from Javax/Jakarta implementations. -
Allow possibility for overriding different JPA properties for each data source by adding
@DataSourceConfig.overridingJpaPropertiesPath
field. By default, it will take the defaultspring.jpa.properties
path.
- HOTFIX: Fix
@EnableJpaRepositories.basePackages
being empty for secondary data sources when@EnableMultiDataSourceConfig.generatedRepositoryPackagePrefix
is not set. Instead, it will be set to the package of the@EnableMultiDataSourceConfig
annotated class followed by.generated.repositories
and then the snake-cased datasource name. - Default
@EnableMultiDataSourceConfig.generatedConfigPackage
changed to the package of the@EnableMultiDataSourceConfig
annotated class followed by.generated.config
instead of@EnableMultiDataSourceConfig.generatedRepositoryPackagePrefix
followed 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:
@MultiDataSourceRepository
has been renamed to@TargetDataSource
for 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
IMultiDataSourceConfig
interface. - 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
MultiDataSource
prefix 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
isMethodSignatureMatching
check 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.