homicki commented on issue #16567:
URL: https://github.com/apache/grails-core/issues/16567#issuecomment-6093017379
We have the same problem on 8.0.0 with `grails-data-hibernate7`, HikariCP
7.0.2, MariaDB 10.11 and MySQL 8.4. We
found it through `HibernateDatastoreConnectionSourcesRegistrar`, which
registers the `dataSource` bean.
The `application.groovy` form fails in the same way. `dataSourceProperties`
(driver settings) is lost as well:
```groovy
dataSource {
properties {
maximumPoolSize = 100
minimumIdle = 10
dataSourceProperties = [connectionCollation: 'utf8mb4_unicode_ci']
}
}
```
The registrar registers the `dataSource` bean as
`#{dataSourceConnectionSourceFactory.create('default',
environment).source}`, so it passes the Spring `Environment`
to the code path that this issue describes. During the context refresh, a
bean type check creates the `dataSource`
bean first. `CachedDataSourceConnectionSourceFactory` then caches the
unconfigured pool under `default`. `HibernateDatastore` builds its connection
sources from the Grails configuration, which does hold the map. But the shared
factory returns the cached pool, so GORM also uses the unconfigured pool.
Proposed fix: build the bean from the Grails configuration
(`create('default', grailsApplication.config)`), as `HibernateDatastore` does.
Alternatively, bind `dataSource.properties` from the `Environment` as a map.
Setting `spring.datasource.hikari.*` does not help:
`DataSourceAutoConfiguration` backs off because a `dataSource`
bean exists.
As a workaround, we define both beans in
`grails-app/conf/spring/resources.groovy`. We need both, because the
framework's factory has already cached the unconfigured pool:
```groovy
dataSourceConnectionSourceFactory(org.grails.datastore.gorm.jdbc.connections.CachedDataSourceConnectionSourceFactory)
dataSource(org.grails.datastore.gorm.bootstrap.support.InstanceFactoryBean,
"#{dataSourceConnectionSourceFactory.create('default',
grailsApplication.config).source}", javax.sql.DataSource)
```
With the workaround, the `dataSource` bean and `HibernateDatastore` share
one `HikariDataSource` with the configured
settings.
--
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]