Results 1 to 9 of 9

Thread: Spring and Multi-tenant approaches

  1. #1
    Join Date
    Jun 2009
    Location
    Sarasota, FL
    Posts
    3

    Default Spring and Multi-tenant approaches

    Hello all,

    I'm wondering if someone could point me to some resources regarding the development of multi-tenant applications with Spring and Hibernate. I've searched around in a few places, and I'm not coming up with much at all. To be clear, there are plenty of articles about multi-tenant architectures, and plenty of articles about Spring/Hibernate, but I've not found anything that ties the two together. Any suggestions?

    Best regards,
    Tim Crowley

  2. #2

    Default

    Multi-Tenant Websites made my work easyer, unfrotunaly never found a corelation Spring/Hibernate.
    LMT

  3. #3
    Join Date
    Nov 2007
    Posts
    122

    Default

    I did a prototype using spring and Hibernate.

    Using spring you can set up multiple data sources, you can inject data source based on user logged in and based on user belongs to which customer.

  4. #4

    Default

    Do you have any code examples of this?

  5. #5
    Join Date
    Nov 2007
    Posts
    28

    Default

    You don't need multiple datasources to do that. In fact, it is possibly to do query rewriting right before Hibernate sends a generated SQL statement off to your database.

    Implementing that query post-processor, you have to have some sort of context from which you can get a specific schema name. In PostgreSQL that will be the "public" schema by default but using multiple schemas together with query rewriting, you can support multi-tenancy by rewriting the schema name.

    Let C12345 be the tenant id, all occurrences of "public" get rewritten in your queries.

    - public.customers ---> C12345.customers

    Maybe you have to tell Hibernate to incorporate schema names in generated queries.

  6. #6
    Join Date
    Nov 2007
    Posts
    122

    Default

    How to tell Hibernate to incorporate schema names in generated queries ?
    We also use native queries as well. I have searched through forums and couldn't find any where on how incorporate schema names ?

    Thanks
    Harshi

  7. #7
    Join Date
    Jun 2011
    Posts
    1

    Default

    Hibernate 4.0 just went beta with multi-tenancy support for schema's. You may want to look into that.

  8. #8
    Join Date
    Oct 2004
    Location
    San Diego, CA USA
    Posts
    58

    Default

    one way I've leveraged Spring in a multi-tenant environment is with Spring Security. The app exposed web services only; each request was a new thread. When the caller authenticated (in our case just HTTPS & basic auth), the current user information is associated with the thread as a thread local. So now anywhere in the code you know who the authenticated user is. Each user is associated with a tenant. There are plenty of ways to skin the cat at this point, given that each thread is associated with a particular tenant. You can do things like query rewriting as someone else mentioned ... or not exactly rewriting in that your queries can all be parameterized to take a tenant code.

  9. #9

    Default

    You could take a look at the Grails plugins for multi tenancy, grails is a rapid development framework with Groovy on top of Spring/Hibernate/etc. One general comment on developing a multi-tenant application would be to look at ways of running multiple instances of the app on a cloud infrastructure, such as Cloud Foundry, Google App Engine, or Amazon Beanstalk. In that case, you might have some front controller that provides a unified front-door to tenants logging in for the first time, but then serves everything for an individual tenant to their individual app instance in the cloud.

    The reason for doing something like this would be to move the compartmentalization of tenants out to the extreme boundries, so you could reliably develop your app without having to worry about gotchas where one tenant accidently gets access to another tenants data via a software defect, or one tenant can't use all the system resources for another tenant. From a systems engineering perspective, there are a lot of things to consider for a multi-tenant system.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •