Navigation through Path to evaluate collection

#1

Hello,

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.

Thanks

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"
       ,ProductData.class)
       .setParameter("key", key)
       .setParameter("id", key)
       ;
    List<ProductData> lists = myquery.getResultList();
    return lists;
}

@Entity
public class ProductData implements Serializable {

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

@Embeddable
public class ApiIdData_ implements Serializable {
   
    private String apiName;
    private String identifier;   
}

 

 

#2

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

Reply