Home » Support » Forum » collection of embedded objects

collection of embedded objects


1. In general, are there any restrictions of the use of @Embedded objects in collections, compared to @Entity?

2. If you have a large nested collection of @Embedded objects, and you remove the parent @Entity, does the remove cascade through the whole collection?

3. Is searching through collections of @Embedded objects more expensive (time) than searching through collections of @Entity?


  1. You can use a collection of embedded objects or simple types (String, Integer) with no particular restrictions (except the ordinary limitations of embedded objects). Use the @ElementCollectionjavax.persistence.ElementCollectionJPA annotationDefines a collection of instances of a basic type or embeddable class.See JavaDoc Reference Page... annotation on the collection to specify fetch policy.
  2. Currently ObjectDB doesn't cascade operations unless it is explicitly required. Since you cannot specify cascade in @ElementCollection you will have to annotate the embedded collection with @OneToManyjavax.persistence.OneToManyJPA annotationDefines a many-valued association with one-to-many multiplicity.See JavaDoc Reference Page... to cascade operations through the collection of embedded objects.
  3. Because of the limitations of embedded objects they are mainly used to save space and improve performance. In many cases queries will run faster when using embedded objects, but not always.
ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)

Is there any advantage to indexing collections of @Embeddable objects?

ie. Suppose I want to query:

SELECT count(a) FROM A a WHERE a.setOfB.value =:value

A is an Entity which has a 'Set<B> set'.

I clearly need an index on B.value. Do I gain anything from an index on A.set?


You cannot define an ordinary index on a field whose type is a user defined embeddable class or a collection of user defined embeddable classes. Therefore, in the above example, setOfB cannot be indexed by its own.

You may define, however, a multi path index on a field in the embedded object. The index is defined in the containing entity class and includes both the entity class field and the embedded class field, e.g.:

public class A {

See the Index Definition page in the ObjectDB manual for more details.

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

Post Reply

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