Search code examples
javagrails

Does Grails 4 supports both multi-datasource and multi-tenant?


I have to implement the both techniques in grails 4:

  1. Multi datasource
  2. Multi tenant

Is it possible? if yes than how?


Solution

  • Yes, Grails 4 does support both, Multi-Datasources and Multi-Tenancy.

    More specifically, Grails supports:

    • Multiple Datasources since Grails 2.x
    • Multiple Tenancy since Grails 3.2

    Multi-Datasources

    From the official documentation, here is how to do Multi-Datasources:

    Multi-Tenancy

    Multi-Tenancy is supported by GORM (the Grails' Object Relational Mapping) since GORM 6.0, introduced with Grails 3.2

    From the official documentation, here is how to do Multi-Tenancy:

    I have succesfully implemented Multi-Tenancy on two different Grails Projects. One of them was on a previously working application, and the adaptation was pretty straightforward using the DISCRIMINATOR approach.

    Here a couple of tutorials on Multi-Tenancy with Grails, one using the DATABASE approach, and the other using the DISCRIMINATOR approach: