ObjectDB ObjectDB

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 @ElementCollection 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 @OneToMany 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

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


To post on this website please sign in.