Hello Community,
We are evaluating Play to re-write our multi-tenant JPA application, we have started using Play Java as most of our team familiar with it.
My problem here is, I am trying to use Hibernate's multi-tenant feature (db per tenant), where I can switch the data sources based on an attribute in Http.Context.args. I am planning to set this attribute for all the requests either using RequestHandler or Global. The actions in my controllers are annotated with the @Transactional.
The actual behaviour is @Transactional is being intercepted before the Global's onRequest and trying to set the JPA EntityManager in Http.Context and failing because It can not find tenant attribute while trying to figure out the specific tenant.
What is the preferred way to intercept all the requests (even better all requests with particular router pattern) before any annotations on actual action being triggered?
My controller action:
@Transactional
public Result list() {
Set<UnitEntity> units = UnitEntity.findAll(UnitEntity.class);
return ok(Json.toJson(units));
}
My RequestHandler:
@Override
public Action createAction(Http.Request request, Method actionMethod) {
return new Action.Simple() {
@Override
public F.Promise<Result> call(Http.Context ctx) throws Throwable {
Map<String, Object> args = ctx.args;
args.put("tenantId", "uchealth");
return delegate.call(ctx);
}
};
}
application.conf
play.http.requestHandler="common.IRequestHandler"
I am missing some basic concepts of the flow. Could please somebody help me?
Thanks,
Raj.