[
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]
|
Hello Guy,
I have a single class in my application that uses the entity manager (it is injected by the container via @PersistenceContext). This class is an abstract DAO class where all my EJB's inherit from in order to access the database. I set the tenant-id property after a transaction is started (i.e. after invoking an EJB method), but before accessing the entity manager. I double checked this by setting a field breakpoint on the EntityManager property and manually checking via the debugger that the property is set. The weird thing is that happens only once, when I execute the same operation again (by reloading the page), I don't get the error.
Any ideas here?
Cheers,
Theo
On Wed, Aug 10, 2011 at 1:15 PM, Guy Pelletier
<guy.pelletier@xxxxxxxxxx> wrote:
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