RESTfulサービスを作成しようとしています。マルチテナントの場合、@AdditionalCriteriaアノテーションを適用します。私は@OneToOneアノテーションを使用してエンティティに参加するときただし、以下の例外が発生します:私はEntityManagerのレベルで、すべてがうまく動作します参加せずにプロパティ[SECURITYID]を設定@OneToOneと組み合わせて@AdditionalCriteriaがQueryExceptionを返す
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 = ?))")
。しかし、@OneToOneを使ってエンティティに参加すると、そのプロパティは存在しません。私は、これが私に間違ったやりかたや、バグかどうかを判断するのに十分な経験がありません。私には、EntityManagerを使用して結合したエンティティをフェッチするように見えます。しかし、私は知識が不足しているために推測しています。私はまた、EntityManagerFactoryレベルでプロパティを設定しようとしましたが、役に立たなかった。
これは私の設定です。 エンティティ:
@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クラス
@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;
}
おかげ& RGDS、 M
でいただきありがとうございます。確かにキャッシングです。私はそれを切って、それは今働く。私は提案されたリンクでそれを読んで、適切な調整を行います。再度、感謝します。 –