matrei opened a new pull request, #16458:
URL: https://github.com/apache/grails-core/pull/16458
Fixes #16455
With GORM for Hibernate, an application without a `dataSource` block got no
`dataSource` bean and no `DataSource` bean at all, although the datastore
created and used a default data source (`jdbc:h2:mem:grailsDB`). Any
`dataSource` block, even one that only repeats a default, made the bean appear.
`HibernateDatastoreSpringInitializer.configureDataSources` only added the
default connection source to the names
`HibernateDatastoreConnectionSourcesRegistrar` registers beans for when the
`dataSource` map was non-empty. It now always includes it, as the `config ==
null` branch already did, since `HibernateDatastore` always creates the default
connection source. Additional `dataSources` are added as before.
Always including the default exposed a second problem.
`configureForDataSource(DataSource)` registers the given data source as a
`dataSource` singleton before the registrar runs, and the registrar only
checked for an existing bean definition, so it replaced the given data source
with its own. The registrar now skips a data source name that is already in use
(`BeanDefinitionRegistry.isBeanNameInUse`), which also covers singletons and
aliases. Before this change, the same replacement happened whenever
`configureForDataSource` was combined with a `dataSource` block.
The change is applied to both `grails-data-hibernate7` and
`grails-data-hibernate5`, which had the same code.
The DataSource section of the guide now says that the default data source is
always available as the `dataSource` bean, also without a `dataSource` block.
### Tests
In both Hibernate modules:
- `HibernateDatastoreSpringInitializerSpec`:
- with no data source configuration, `dataSource` is the only `DataSource`
bean, it is the datastore's default data source, and it connects to
`jdbc:h2:mem:grailsDB`
- with only `dataSources.books` configured, both `dataSource` and
`dataSource_books` are registered
- the data source passed to `configureForDataSource` remains the
`dataSource` bean
- `HibernateDatastoreConnectionSourcesRegistrarSpec`: a `dataSource`
registered beforehand as a bean definition or as a singleton is kept
Without the fix, the first two initializer features fail (checked with
Hibernate 7). With the old `containsBeanDefinition` check in the registrar, the
`configureForDataSource` feature fails in both modules, and the singleton
registrar feature fails (checked with Hibernate 7).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]