Tenant datasource

Hi Konstantin,

Regarding this topic CUBA multi-tenant with database per tenant i have some questions. I attached a test project.

I created a class TenantConfigStorage in order to ovveride ConfigStorage, so the Configs created to be stored in tenant database, not in main database.
After user log in, a screen will appear, and the user must choose a database. After that i set the tenantDbAddress in session attribute.
On close of this screen i have added a closeListener, where i read a configuration stored in tenant database, and display it on main screen on a label.

The Config

@Source(type = SourceType.DATABASE)
public interface SocietateConfig extends Config  {

    void setInit(String init);

    String getInit();

    String getDenumire();

    void setDenumire(String denumire);

When i call the setter method of config, it is saved in tenant database but when i want to read it, the value is null.

ExpertContab.zip (319.9K)

1 Like


After some debugging i find out that method determineCurrentLookupKey from TenantsRoutingDatasource is called twice. First call, when i set the value, is reading dbAddress from session of u1.
But when it’s called for get, dbAddress is reading from admin user, ClientCacheManager.

What can i do to be read by user is authenticated?

Thank you!!


Hi Sorin,

ConfigStorage uses in-memory cache for better performance, and it would be quite difficult to adapt it for the DB-per-tenant architecture. So I’d recommend using configuration interfaces only for settings shared between all tenants.

You can use regular entities and custom screens for tenant-specific settings. It’s not as convenient as using config interfaces but you’ll have full control over where your settings are stored. Moreover, you will easily be able to create user-friendly UI for managing these settings by the tenants personnel.