You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Hibernate 4 Multi Tenancy Feature Support [SPR-10823] #15449
At the moment there is no way to provide bean reference for MultiTenantConnectionProvider. This is necessary because an implementation of MultiTentnatConnectionProvider needs to be wired to a DataSource. The current version of LocalSessionFactoryBuilder sets only the dataSource property to a bean reference. Since currently any implementation of MultiTenantConnectionProvider is not Spring managed, users are forced to define another DataSource/Connection Pool with hard coded db properties or a non Spring way of accessing those properties
Actually, just like "hibernate.tenant_identifier_resolver", the "hibernate.multi_tenant_connection_provider" property not only accepts a class name but also an instance. So you could pass in a MultiTenantConnectionProvider instance through a <map> specified against LocalSessionFactoryBean's "hibernateProperties", or call LocalSessionFactoryBuilder's getProperties().put(...) method accordingly.
That said, to make this first-class in Spring 4, I've added setMultiTenantConnectionProvider and setCurrentTenantIdentifierResolver methods to both LocalSessionFactoryBuilder and LocalSessionFactoryBean.
I was not aware of the method you have mentioned. Thank you! I have actually done the same thing you have described as a temporary fix. Extended LocalSessionFactoryBuilder and wrote duplicate LocalSessionFactoryBean with a tiny change to use the custom LocalSessionFactoryBuilder.
Activity
spring-projects-issues commentedon Sep 3, 2013
Juergen Hoeller commented
Actually, just like "hibernate.tenant_identifier_resolver", the "hibernate.multi_tenant_connection_provider" property not only accepts a class name but also an instance. So you could pass in a MultiTenantConnectionProvider instance through a <map> specified against LocalSessionFactoryBean's "hibernateProperties", or call LocalSessionFactoryBuilder's getProperties().put(...) method accordingly.
That said, to make this first-class in Spring 4, I've added setMultiTenantConnectionProvider and setCurrentTenantIdentifierResolver methods to both LocalSessionFactoryBuilder and LocalSessionFactoryBean.
Juergen
spring-projects-issues commentedon Sep 3, 2013
I. Benyaminov commented
I was not aware of the method you have mentioned. Thank you! I have actually done the same thing you have described as a temporary fix. Extended LocalSessionFactoryBuilder and wrote duplicate LocalSessionFactoryBean with a tiny change to use the custom LocalSessionFactoryBuilder.
My answer on stackoverflow: http://stackoverflow.com/questions/16213573/setting-up-a-multitenantconnectionprovider-using-hibernate-4-2-and-spring-3-1-1/18392586#18392586
spring-projects-issues commentedon Oct 25, 2013
andrew chen commented
Juergen Hoeller's suggestion seem to work for me:
spring-projects-issues commentedon May 29, 2015
Amit commented
I tried following the suggest from
@JuergenHoeller with JPA but got an NPE (http://pastebin.com/E3RwNt1y). The config is - http://pastebin.com/ZNdkzkKT. It seems that the AbstractEntityManagerFactoryBean.getObject() is called before AbstractEntityManagerFactoryBean.afterPropertiesSet(). Any idea what could be wrong?