I tried setting the tenant-id at runtime and it works. I'm using EclipseLink in a container-managed environment, i.e., the EntityManager is injected via @PersistenceContext.
I still have the following question: Is there a way to bind the tenant-id to the HttpSession session. I'm frequently getting the following error: No value was provided for the session property [eclipselink.tenant-id].
Currently, I'm setting the tenant-id for every method call to the entity manager, which is rather tedious. Is there a more elegant way?
Thanks for your answer. Will try it out and provide feedback.
Regarding @Unique: it's an JPA annotation that enforces a uniqueness constraint on a database column. And my question was referring to whether this can be used in a multi-tenant environment, i.e. Enforcing uniqueness only within a tenant.
Yes, EclipseLink's multitenant supports adding and removing
tenants at runtime. You are not restricted by the persistence.xml
file. Below are a few links that describe our support and usage
further. In a nutshell you decorate your multitenant entities with
@Multitenant and @TenantDiscriminatorColumns (optional) and can
provide tenant id's at the Persistence unit, entity manager factor
or entity manager level based on your requirements/needs.
As for @Unique, I'm not aware of this annotation and its usage in
EclipseLink's multitenant solution. Where did you see this used?
Cheers,
Guy
On 23/07/2011 11:21 AM, Theodor Richard wrote:
Hi,
I want to
convert my current Java EE 6 app to support multi-tenancy.
At first, I was gonna do it "manually" by adding a tenant-id
into every entity and include it in the every query. But
then, I came across EclipseLink's support for
multi-tenancy.
My
question: I want to be able to add/remove tenants at
runtime. I don't need any tenant-specific customization.
Does EclipseLink support this? And how does @Unique behave?
Is it restricted to one tenant or does it apply across all
tenants? I watched the screencast and read the wiki about
Multi-tenancy. It looks like you can only add tenants at
deployment time (by changing the persistence XML file)