I'm trying to create a RESTful service. For multi tenancy I'm applying the @AdditionalCriteria annotation. However, when I join an entity using the @OneToOne annotation the following Exception is raised:
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
[SECURITYID]. 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.
Query: ReadObjectQuery(name="readObject" referenceClass=Addresses
sql="SELECT id, city, country, postalcode, province, security_id, street
FROM addresses WHERE ((id = ?) AND (security_id = ?))")
I set the property [SECURITYID] at EntityManager level and without the join everything works just fine. But when I join an entity using the @OneToOne I see that property is not there. I don't have enough experience to determine if this is caused by me doing something wrong or if this is a bug. To me it looks like a different EntityManager is used to fetch the joined entity. But I'm guessing because of me lacking in knowledge. I also tried to set the properties on EntityManagerFactory level but to no avail.
Here is my setup. Entity:
@Entity
@AdditionalCriteria("this.securityId=:SECURITYID")
@Table(name = "tasks", catalog = "catalog", schema = "schema")
@XmlRootElement
@NamedQueries(
{
@NamedQuery(name = "Tasks.findAll", query = "SELECT t FROM Tasks t")
})
public class Tasks implements Serializable
{
...
@OneToOne(fetch=FetchType.EAGER)
@JoinColumn(name="service_address_id")
private Addresses serviceAddress;
...
}
RESTFacade class
@Stateless
@Path("tasks")
public class TasksFacadeREST extends AbstractFacade<Tasks>
{
@PersistenceContext(unitName = "UnitName")
private EntityManager em;
...
@java.lang.Override
protected EntityManager getEntityManager()
{
// Temp! REMOVE WHEN DONE
sessionId = "123456789";
Identifier.setIdentity(em,sessionId);
em.setProperty("SECURITYID",Identifier.securityId);
em.setProperty("USERID",Identifier.userId);
return em;
}
Thanks & Rgds, M