Fork me on GitHub

Mapping Collection Fields

The collection-descriptor maps a collection attribute into JCR nodes or in a multivalue property.

Based on our model defined here, the following collection-descriptor is used to map the “paragraphs” field into the JCR node called “paragraphs”.

      fieldName="paragraphs" jcrName="paragraphs"
      elementClassName="org.apache.jackrabbit.ocm.testmodel.Paragraph" />
  <!-- other field, bean and collection mapping here !-->

  <field-descriptor fieldName="path" path="true" />
  <field-descriptor fieldName="text" jcrName="my:text"/>

The collection-descriptor contains the elementClassName attribute which specify the collection element class. A class descriptor for the element class has also to be defined.

The JCR Structure

Following our example, the resulting JCR structure is:

      my:text = "This is the content of para1"
      my:text = "This is the content of para2"
  ... other subnodes for page1 ...

By default, the persistence manager will create a subnode (/mysite/page1/paragraphs). This one will contains the different paragraphs.

As explained in the following sections, it is possible to map to another JCR structure. It is also possible to use another name for the jcr node names (see above).

Supported Collection and Map Types

The OCM framework is supporting the following java types:

  • Collections Collection, List, Set, ArrayList, Vector, HashSet
  • Maps Map, HashMap

Using Another Collection or Map

It is possible to support other Collection or Map types with the ManageableCollection interface.

Using Another Collection Converter


Predefined Collection Converters


Building your own Collection Converters