Reputation: 641
Our application project is an OSGI bundle using JPA with EclipseLink and JTA, and needs single-table multi-tenancy, where tenant ID comes from a REST request. From what I've read and tried, it almost seems that is impossible:
PersistenceContext
(EntityManager
) with the appropriate property.@PersistenceUnit
does not get injected and Persistence.createEntityManagerFactory
does not work), according to http://tomee.apache.org/jpa-concepts.html.Am I missing something? Or is this literally impossible to do?
Upvotes: 0
Views: 231
Reputation: 373
You can set multitenant/discriminator properties in the entity manager for a request. But it is not safe for multi-threading and lazy initialization.
I tried our CMobileCom JPA that supports single-table multitenancy. For each tenant, a new EntityManager should be used. That is, an EntityManager should not be shared to access data for multiple tenants. This is also true for EclipseLink.
Disclaimer: I am a developer of CMobileCom JPA, a light weight JPA implementation for Java and Android.
Upvotes: 0