Home » Support » Forum » Navigation to Collection Elements

Navigation to Collection Elements

#1

Greetings ObjectDB team,

Suppose I have a collection typed field (list/map/set...) in my persistent object of class X.

Can I navigate (as opposed to using JOIN) to individual elements (in JPA & JDO) ?

e.g.:

x.list.get(10)

x.map.get("key")

x.list.get(10).get("key") // the element itself is a map

How about arrays like x.array[1] and x.array[1][2] ?

Thanks & Best Regards

#2

Yes, you can navigate from any managed entity object to any other reachable managed entity object. All the expressions that you wrote are valid, if x is a managed entity object (or persistent object in JDO) in both JPA and JDO, assuming the owner EntityManager / PersistenceManager is open.

If the referenced objects are not already in memory they will be loaded automatically from the database. This is sometimes referred to as transparent persistence (or transparent activation / retrieval).

When using ObjectDB you can also use these expressions in queries but it is not recommended, because it is not JPA/JDO portable (it is an extension of ObjectDB) and it also leads to performance penalty.

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)
#3

Thank you for your fast reply.

I really meant it to be done in JPA/JDO queries.

How about arrays like x.array[1] and x.array[1][2] ?

If such navigations in queries lead to performance penalty, how slow is it and would you recommend something better ?

Thanks

#4

If you query a class that does not have too many objects (e.g. up to one million) then every supported query might be fine.

Indexes, for example, are not supported in handling such expressions.

Indexes are supported in handling more conventional collection expressions (by using JPA's JOIN or JDO's contains).

The array expressions that you wrote are not supported in queries, and anyway, collections are preferred over arrays when using JPA/JDO (and they might be even more efficient).

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)

Post Reply

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