SAP
SAP

Reputation: 468

How do I traverse a relationship in a WHERE clause with OpenJPA?

I am new to JPA and OpennJPA. I have two entities UserDmo and SupplierDmo. Each Supplier can have several users and this relationship is established as follws,

In UserDmo,

Column(name="id_supplier")
private long idSupplier;

@ManyToOne(optional=true)
@JoinColumn(name="ID_SUPPLIER")
private SupplierDmo supplier;

In here column ID_SUPPLIER is the FK with referenced by ID column of the SupplierDmo. Using these two entities I tried to obtain result by following query.

SELECT u.id, u.modifiedDate FROM UserDmo u JOIN u.idSupplier s WHERE s.id = 1

But I got, Error message: Attempt to query field "s.id" from non-entity variable "s". Perhaps you forgot to prefix the path in question with an identification variable from your FROM clause?

I really appreciate your help on this

Upvotes: 2

Views: 1517

Answers (1)

Rick
Rick

Reputation: 3840

Try something like this :

SELECT u.id, u.modifiedDate FROM UserDmo u WHERE u.supplier.id = 1

Upvotes: 1

Related Questions