0

While trying to save some data to the datastore belonging to a specific tenant in BootStrap.groovy I am getting the following error.

org.grails.datastore.mapping.multitenancy.exceptions.TenantNotFoundException: Tenant could not be resolved outside a web request

I am using SessionTenantResolver as tenantResolver class config in application.yml

  multiTenancy:
                mode: DATABASE
                tenantResolverClass: org.grails.datastore.mapping.multitenancy.web.SessionTenantResolver

I have tried wrapping the tenant aware query inside withId as given below

withId("tenant1") {
    User tenant1Admin = new User()
    tenant1Admin.username = "tenaant1admin"
    tenant1Admin.password = "password"
    tenant1Admin.save(flush:true)
}

User.groovy (generated by s2-quickstart)

class User implements MultiTenant<User>, Serializable {
...
}

What I am trying to achieve is to store super admin related data to the default datastore and other admins/users auth info to the datastore of the tenant they belong to.

Also, if I create only the super admin from Bootstrap.groovy and save it to the default data store, how should I be doing it?

Satish
  • 31
  • 1
  • 7
  • I've had the same issue. At the end, i've added my bootstrap code to the `Application.groovy`. – gregorr Aug 21 '17 at 15:22
  • @gregorr adding the code in Application.groovy worked for created domains, but didn't work for auth domain generated with s2-quickstart commands. I am getting following exceptions `Exception in thread "main" org.springframework.orm.hibernate5.HibernateSystemException: No Session found for current thread; nested exception is org.hibernate.HibernateException: No Session found for current thread ` – Satish Aug 25 '17 at 20:26
  • Also, could any one explain differences between Application.groovy and Bootstrap.groovy. The question exist but does not have an answer [link](https://stackoverflow.com/questions/41797922/what-is-the-difference-between-application-groovy-and-bootstrap-groovy-in-grails) – Satish Aug 25 '17 at 20:33

0 Answers0