Skip to content

Hibernate 4 Multi Tenancy Feature Support [SPR-10823] #15449

Closed

Description

@spring-projects-issues

I. Benyaminov opened SPR-10823 and commented

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


Affects: 3.2.4

Reference URL: http://docs.jboss.org/hibernate/orm/4.1/devguide/en-US/html/ch16.html#d5e4605

Issue Links:

Referenced from: commits 542b5b2

Activity

  1. spring-projects-issues commented on Sep 3, 2013

    @spring-projects-issues
    CollaboratorAuthor

    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

  2. spring-projects-issues commented on Sep 3, 2013

    @spring-projects-issues
    CollaboratorAuthor

    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

  3. spring-projects-issues commented on Oct 25, 2013

    @spring-projects-issues
    CollaboratorAuthor

    andrew chen commented

    Juergen Hoeller's suggestion seem to work for me:

    <property name="hibernateProperties">
        <map>
            <!--<prop key="hibernate.hbm2ddl.auto">update</prop>-->
            <entry key="hibernate.dialect" value="org.hibernate.dialect.PostgreSQL82Dialect"/>
            <entry key="hibernate.multiTenancy" value="SCHEMA"/>
            <entry key="hibernate.tenant_identifier_resolver" value="com.jazva.multitenant.dao.CurrentTenantIdentifierResolverImpl"/>
            <entry key="hibernate.multi_tenant_connection_provider" value-ref="multiTenantConnectionProvider"/>
        </map>
    </property>
    
  4. spring-projects-issues commented on May 29, 2015

    @spring-projects-issues
    CollaboratorAuthor

    Amit commented

    I tried following the suggest from @Juergen Hoeller 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?

  5. added
    in: data
    type: enhancement
    on Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: datatype: enhancement

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions