Agora estou com o seguinte problema na hora de executar a app: ERROR context.GrailsContextLoader - Error initializing the application: Error creating bean with name 'transactionManagerPostProcessor': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.service.spi.ServiceException: Unable to instantiate specified multi-tenant connection provider [exemplo.MultiTenantConnectionProviderImpl]
Aparentemente está ocorrendo algum problema na hora de instanciar a classe MultiTenantConnectionProviderImpl. Configurei meu DataSource.groovy conforme abaixo (demais campos omitidos):
hibernate {
cache.use_second_level_cache = true
cache.use_query_cache = false
cache.provider_class='org.hibernate.cache.EhCacheProvider'
//cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory' // Hibernate 3
cache.region.factory_class = 'org.hibernate.cache.ehcache.EhCacheRegionFactory' // Hibernate 4
/* configuração do multi-tenant */
tenant_identifier_resolver = 'exemplo.MultiCurrentTenantIdentifierResolver'
hibernate.multi_tenant_connection_provider = 'exemplo.MultiTenantConnectionProviderImpl'
multiTenancy = 'SCHEMA'
}
e criei 3 classes dentro de src/groovy/exemplo (vou colocar apenas a provider que é a que está causando problema):
package exemplo
import java.sql.Connection;
import java.sql.SQLException;
import org.hibernate.HibernateException
import org.hibernate.MultiTenancyStrategy
import org.hibernate.Session
import org.hibernate.SessionFactory
import org.hibernate.cfg.Configuration
import org.hibernate.service.jdbc.connections.spi.*
import javax.sql.DataSource
class MultiTenantConnectionProviderImpl extends AbstractMultiTenantConnectionProvider {
private final ConnectionProvider acmeProvider = ConnectionProviderUtils.buildConnectionProvider( "acme" );
private final ConnectionProvider jbossProvider = ConnectionProviderUtils.buildConnectionProvider( "jboss" );
@Override
protected ConnectionProvider getAnyConnectionProvider() {
return acmeProvider;
}
@Override
protected ConnectionProvider selectConnectionProvider(String tenantIdentifier) {
if ( "acme".equals( tenantIdentifier ) ) {
return acmeProvider;
}
else if ( "jboss".equals( tenantIdentifier ) ) {
return jbossProvider;
}
throw new HibernateException( "Unknown tenant identifier" );
}
}
alguém sabe porque pode estar ocorrendo este problema? estou a um bom tempo procurando a causa mas ainda não encontrei.
Postei o problema em outro fórum e obtive a resposta abaixo:
"Hi Dyego
I spoke about the plugin with Burt (the creator of the plugin) and I was asking some basic questions and the I have found, the plugin is not tested in real use. Unfortunately. And then I have found that for example: if you create domain classes and then you turn on multitenancy. In that case the domain classes are not created as a database tables in your database. I was like WAT? :) yes, he told reasonable answers why not. But again, I thought there should be some default behaviour and I would expect that the tables are going to be created. He told, just raise a new request and I am going to do it.
So, currently, you need to take care about everything.
Ondrej K."
Assim, acabei voltando pro hibernate 3 e usando o plugin MultiTenant-SingleDB, apanhei um pouco para criar o SystemUser, mas acabou funcionando.
Dyego Mota,
Pode me passar o passo a passo ?
Olá Lucas,
Então, no fim das contas eu não usei o Hibernate 4.
Abs,