-
-
Notifications
You must be signed in to change notification settings - Fork 956
really hard to initialize second datasource with HibernateGormAutoConfiguration #14660
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I also thought HibernateDatastoreSpringInitializer#configureForDataSource() was a really cool method, until I saw that is is hard-coded to register the "dataSource" bean:
|
What appears to be another bug in HibernateDatastoreSpringInitializer:
So I get an exception: If it's intended that we define the beans ourselves, then please document this somewhere. Thanks! |
And there's also this code:
I had to initialize the HibernateDatastoreSpringInitializer with the datasources in the opposite order to make sure that "transactionManager_dataSource_vertica" is registered before "transactionManager":
|
HibernatePluginSupport made sure to add these properties to the session factory:
Without them I end up with two ConfigurableLocalSessionFactoryBeans which both have field "dataSourceName" set to "DEFAULT" even though the second bean has field "dataSource" set to the vertica data source. This of course causes problems in building the session factory proxy. Am I doing something wrong? |
Hi, I couldn't find the issue tracker for gorm-hibernate4-spring-boot, so please help me find it if this one is GSP-specific.
I wanted to set up a second data source (primary data source against postgres and second datasource against Vertica). We have the same code in a Grails project that works fine.
Here are the issues I have found so far:
But HibernateDatastoreSpringInitializer is hardcoded as:
So adding a second datasource actually required:
a) subclassing HibernateGormAutoConfiguration with my own auto configuration class that copies/pastes the code except to insert the line:
b) add HibernateGormAutoConfiguration to the excludes list of auto configuration, or else both run
But the PostInitializingHandling bean is registered once per datasource, we can see this in a for loop over datasources:
So we end up with an exception:
For my second data source I desire the ultimate data source's name to be "dataSource_vertica". So that's the name I've put into the HibernateDatastoreSpringInitializer.dataSources field.
But you can see above the suffix has been determined as _dataSource_vertica, so now the session factory has been named "sessionFactory_dataSource_vertica" instead of just "sessionFactory_vertica". And it's looking for hibernate properties "hibernate_dataSource_vertica".
So I think the "suffix" and "prefix" variables should not include dataSourceName.
But as I showed in grails/grails-gsp-spring-boot#1, HibernateGormAutoConfiguration has:
where getDatastoreConfiguration() is defined as:
You see the same data store configuration is used for both datasources, whereas I wanted to use a different one for each.
The text was updated successfully, but these errors were encountered: