Query to find object from element of a contained collection

#1

I have an OrderData class, containing an OrderItemData collection, i would like to find OrderData elements by OrderData.items.itemId.

I cant get a proper query with MEMBER OF or IN. Does anyone have an idea on how i could formulate that as Typed or CriteriaBuilder query?

Thanks.

 

@Entity
public class OrderData implements Serializable {
    ...
    private OrderItemData[] items = null;
    ...
}

public class OrderItemData implements Serializable {
    ...
    private String itemId = null;
    ...
}

 

 

 

#2

Although serializable objects that are not entity or embeddable classes are supported by ObjectDB, the recommendation is to avoid using them when possible due to their limitations.

Try to define OrderItemData as en embeddable class.

In addition, replace the ordinary array with a collection (e.g. ArrayList).

You may also need to use a multi variable query with JOIN.

ObjectDB Support
#3

Thank you for the fast support, indeed the few classes that were not entity nor embeddable have been set as embeddable since then as i had issues with sync. I still have few issues with the EntityManager and sync that will be the topic of another thread. I will have a try with JOIN, thank you. 

Reply