You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would like to know if it's possible to use Micronaut Data JDBC in conjunction with:
Schema-mode multitenancy
The @TenantId annotation
This is because my particular workflow doesn't trigger from an HTTP request (or anything supported by any of the built-in tenant resolvers bundled with Micronaut). Instead, tenants come from data fetched by my app from external systems at runtime.
My current code looks like this:
Application.yml
micronaut:
data:
multi-tenancy:
mode: SCHEMA# One datasource, which contains multiple schemas with identical tables I want to map to one entitydatasources:
default:
url: jdbc:postgresql://localhost:5444/postgresdialect: postgresdriver-class-name: org.postgresql.Driverusername: changemepassword: changeme
@SingletonclassMyService {
privatefinalMyRepositorymyRepository;
MyService(finalMyRepositorymyRepository) {
this.myRepository = myRepository;
}
@io.micronaut.scheduling.annotation.Scheduled(fixedRate = "5m")
publicvoiddoStuff() {
// Tenants are dynamically fetched from external systems (HTTP calls or DB calls), I'm manually setting the values here to keep the example simple// Saving to schema AfinalvarmyEntity = newMyEntity("schema_a", null, "any value");
myRepository.save(myEntity);
// Updating to schema A (assuming "1" is the id of the previous entity)finalvarupdatedEntity = newMyEntity("schema_a", 1, "updated value");
myRepository.update(myEntity);
// Saving to schema BfinalvarmyEntity2 = newMyEntity("schema_b", null, "any value");
myRepository.save(myEntity2);
// Updating to schema B (assuming "1" is the id of the previous entity)finalvarupdatedEntity2 = newMyEntity("schema_b", 1, "updated value");
myRepository.update(myEntity2);
}
}
But that leads to the exception ERROR: column \"column_a\" of relation \"my_entity\" does not exist because the tenant seems to not be resolved.
My question is if this scenario is supported by Micronaut Data JDBC and, if not, if I should rely to some other mechanism instead.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Hi there!
I would like to know if it's possible to use Micronaut Data JDBC in conjunction with:
@TenantIdannotationThis is because my particular workflow doesn't trigger from an HTTP request (or anything supported by any of the built-in tenant resolvers bundled with Micronaut). Instead, tenants come from data fetched by my app from external systems at runtime.
My current code looks like this:
Application.yml
Repository
Entity
Client code
But that leads to the exception
ERROR: column \"column_a\" of relation \"my_entity\" does not existbecause the tenant seems to not be resolved.My question is if this scenario is supported by Micronaut Data JDBC and, if not, if I should rely to some other mechanism instead.
Thanks in advance!
Beta Was this translation helpful? Give feedback.
All reactions