1 Reply Latest reply on May 17, 2013 7:08 AM by Tom Eicher

    How to use Hibernate Multi Tenancy in AS7 EE enviroment

    Tom Eicher Newbie

      Hello,

       

      I want/need to make use of Hibernates Multi Tenant Capabilities for a EE6 application inside AS7.

      There is little to be found in documentation and examples, however.

      Adding properties hibernate.multiTenancy and hibernate.multi_tenant_connection_provider to persistence.xml seems to trigger some response.

      Now how would I use this in an AS7 (or WildFly) environment ?

       

      Since I am not allowed to create connections myself, I guess I need to define all tenant datasources in standalone.xml

       

      Okay, then my AbstractMultiTenantConnectionProvider could lookup those from JNDI and provide them as needed. Yes? No? Better ideas?

       

      And where does the tenantIdentifier in protected ConnectionProvider selectConnectionProvider(String tenantIdentifier) come from ?

      If I have this identitier e.g. as a field in my User / Login entity, where / how would I setup this so that a request for User X goes to it's correct database, i.e. how do I setup a "tenancy context" ...?

       

      Any comment, links, explanations and examples are greatly welcome.

      Thanks, Cheers, Tom.

        • 1. Re: How to use Hibernate Multi Tenancy in AS7 EE enviroment
          Tom Eicher Newbie

          Okay, so it basically works as outlined above.

           

          Now the CurrentTenantIdentifierResolver I provided is not tied in any way into the EE server.

          I currently have (for other purposes) a @SessionScoped bean (say, MyContext) in my Wicket -> EJB integration.

          If my CurrentTenantIdentifierResolver implementation had access the MyContext, it really could decide on the right tenant identifier for the current request's user...

           

          Any ideas ? Cheers, Tom.