[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] EclipseLink Multi-tenancy: No value was provided for the session property [eclipselink.tenant-id]

Hi Theo,

Are you setting your tenant properties after a begin transaction call? You're tenant properties should be set on the EM only after a begin transaction call and before any operations are performed on that EM.

Cheers,
Guy

On 10/08/2011 4:22 AM, Theodor Richard wrote:
Hi,

I'm developing a multi-tenant Java EE 6 application (where tenants share a single table) with container managed @PersistenceContext injection. I keep getting the following exception:

Exception [EclipseLink-6174] (Eclipse Persistence Services - 2.3.0.v20110604-r9504): org.eclipse.persistence.exceptions.QueryException
Exception Description: No value was provided for the session property [eclipselink.tenant-id]. This exception is possible when using additional criteria or tenant discriminator columns without specifying the associated contextual property. These properties must be set through Entity Manager, Entity Manager Factory or persistence unit properties. If using native EclipseLink, these properties should be set directly on the session.

I set the multi tenant property for every transaction as follows:

em.setProperty(PersistenceUnitProperties.MULTITENANT_PROPERTY_DEFAULT, checkNotNull("tenant-id"))

where em is the EntityManager. I get the above exception, although I set the property. I also debugged the code to make sure that the property is set (through em.getProperties()), and I was able to see that it's set. When I reload the page (i.e. start another transaction), it works.

How can I prevent this exception?

Thanks,
Theo