Open benheilers opened 9 years ago
I also thought HibernateDatastoreSpringInitializer#configureForDataSource() was a really cool method, until I saw that is is hard-coded to register the "dataSource" bean:
applicationContext.beanFactory.registerSingleton(defaultDataSourceBeanName, dataSource)
What appears to be another bug in HibernateDatastoreSpringInitializer:
if(!beanDefinitionRegistry.containsBeanDefinition("entityInterceptor")) {
entityInterceptor(EmptyInterceptor)
}
...
entityInterceptor = ref("entityInterceptor$suffix")
So I get an exception: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'entityInterceptor_dataSource_vertica' is defined
If it's intended that we define the beans ourselves, then please document this somewhere.
Thanks!
And there's also this code:
if (!beanDefinitionRegistry.containsBeanDefinition("transactionManager")) {
"transactionManager$suffix"(GrailsHibernateTransactionManager) { bean ->
bean.autowire = "byName"
sessionFactory = ref(sessionFactoryName)
dataSource = ref(dataSourceName)
}
}
I had to initialize the HibernateDatastoreSpringInitializer with the datasources in the opposite order to make sure that "transactionManager_dataSource_vertica" is registered before "transactionManager":
//NOTE: change from parent class, add vertica data source, force ordering of vertica datasource first
initializer.dataSources = [ 'dataSource_vertica', 'dataSource' ] as LinkedHashSet<String>
HibernatePluginSupport made sure to add these properties to the session factory:
dataSourceName = datasourceName
sessionFactoryBeanName = "sessionFactory$suffix"
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 #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.