1 2 Previous Next 16 Replies Latest reply on Feb 19, 2014 9:16 AM by nathan dennis Go to original post
      • 15. Re: How to implememt JPA / Hibernate Multi Tenancy with DATABASE Strategy?
        Deepak Angeswar Newbie

        I am using Hibernate 4.2 & EJB 3.0. I following the strategy outlined in https://docs.jboss.org/hibernate/core/4.2/devguide/en-US/html/ch16.html

         

        Separate Schema approach.

        I have added the following in my persistance.xml file

         

        Code:

        <property name="hibernate.multi_tenant_connection_provider"         value="com.lombardrisk.util.multitenancy.MultiTenantProvider" />

        <property name="hibernate.tenant_identifier_resolver" value="com.lombardrisk.util.multitenancy.SchemaResolver" />

        <property name="hibernate.multiTenancy" value="SCHEMA" />

         

        But for some reason it appears those 3 properties are completely ignored. I have tired commenting the properties - hibernate.multi_tenant_connection_provider & hibernate.tenant_identifier_resolver

         

        (I was hoping to see an exception - since as per the documentation - It is an error to attempt to open a session without a tenant identifier using this strategy. Additionally, a org.hibernate.service.jdbc.connections.spi.MultiTenantConnectionProvider must be specified.)

         

        http://stackoverflow.com/questions/19348477/multitenancy-with-hibernate-4-0-with-separate-schema-approach

         

        The above link also points to the same problem - but does not explain how the problem was solved. Would appreciate if some one can point me to the right direction.

         

        Note: I have also tried removing the classes MultiTenantProvider & SchemaResolver from my ear file and deployed the App in Jboss - but still there is no exception and the app always uses the default schema - so it looks like - those 3 properties are completely ignored in my persistance.xml

         

        regards

        D

        • 16. Re: How to implememt JPA / Hibernate Multi Tenancy with DATABASE Strategy?
          nathan dennis Expert

          i need to just get a complete sample project going in github for this and remove some of the obscurities. I just havent had time yet. It does work using JPA with this hibernate implementation (which was really what i was trying to accomplish  for 2LCing reasons). There's just a lot of trial and error ... and reading api code because of the limited examples right now. Side note,, one thing i found that speeded up my implementation of this in an app server environment was to threadlocal the datasource. It would bottleneck at the JNDI lookup under load. only performing that JNDI lookup once per request really got the connection pool humming like it was suppose to. Releasing the connection after every statement was just making that lookup work too much. @Sunny Singh that hibernate.enable_lazy_load_no_trans is priceless for using this with spring mvc and JSPs. thank you. I had overlooked that parameter.

          1 2 Previous Next