Yes, I’m already using Hibernate’s multi tenancy support, so I can provide the right EntityManager to each tenant.
My problem is how to tell Axon to use the right EntityManager.
When the CommandBus calls TransactionManager.startTransaction() he doesn’t provide any parameter, so the TransactionManager can’t know the tenant-id
and can’t use the tenant’s EntityManager to get the transaction.
The JpaEventStore has the same problem with the EntityManagerProvider: getEntityManager() has no way to know the tenant-id.
A possible solution is to have a CommandBus and a JpaEventStore for each tenant and route each request to the API to the tenant’s CommandBus.
I wonder if is possible to use a single instance of CommandBus and a single instance of JpaEventStrore for all tenants…