Home » Support » Forum » Navigation through Path to evaluate collection

Navigation through Path to evaluate collection



I need to evaluate a field ("identifier") which is situated in a collection, within an entity. As stated in the documentation it is not possible to navigate there with the dot operator since its a collection. Is it there a way to evaluate this field? Here is the query, the entity and the related embeddable class.


public synchronized List<ProductData> getList(String key){

   TypedQuery<ProductData> myquery = em.createQuery(
       "SELECT item FROM ProductData item "+
       "WHERE item.sku =: key "+
       "OR id MEMBER OF :item.apiId.identifier "+
       "ORDER BY item.sku DESC"
       .setParameter("key", key)
       .setParameter("id", key)
    List<ProductData> lists = myquery.getResultList();
    return lists;

public class ProductData implements Serializable {

    @Id @GeneratedValue
    private long id;
    @ElementCollection(fetch = FetchType.EAGER)
    private List<ApiIdData_> apiId;

public class ApiIdData_ implements Serializable {
    private String apiName;
    private String identifier;   




You shoud use JOIN:

SELECT item FROM ProductData item JOIN item.identifier id
WHERE item.sku = :key OR id = :id
ORDER BY item.sku DESC

You may also try this (not valid JPQL but may be supported by ObjectDB):

SELECT item FROM ProductData item
WHERE item.sku = :key OR item.apiId.identifier = :id
ORDER BY item.sku DESC
ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)

Post Reply

To post a reply and/or subscribe to update notifications - please login