How you add a repository item to a Set, List, Map, or Array partly depends on how you use the cascade attribute. For example, the previous definition of the books_written property might be modified to set cascade to update:

<property name="books_written" data-type="set"
          component-item-type="book"
          column-name="book_id"
          cascade="update"/>

This setting makes it easier for you to keep the book repository items synchronized with the author repository items that refer to them. See the Cascading Data Relationships section. You can add a book item to a set of items in the books_written property like this:

Repository gsa = ...;
RepositoryItem newBook = getRepository().createItem("book");
Set books_written = (Set) author.getPropertyValue("books_written");
books_written.add(newBook);

If the books_written property does not have cascade="update", you must add the item with the addItem() method (thus inserting the row in the database) before you add it to the list:

Repository gsa = ...;
RepositoryItem newBook = getRepository().createItem("book");
getProfileRepository().addItem(newBook);
Set books_written = (Set) author.getPropertyValue("books_written");
books_written.add(newBook);

Remember that in each of these cases, it is most efficient to ensure that all method calls are performed in a single transaction. See Repositories and Transactions in the SQL Repository Architecture section.

Prohibiting Duplicate Values

You can prohibit duplicate values in multi-item properties of type List and Array by setting the repository component property prohibitCollectionDuplicates to true. By default, this property is set to false. The repository definition of individual properties can override the repository-level setting. For example:

<property name="color"
                column-names="color" data-type="list"
                component-data-type="string">
   <attribute name="prohibitDuplicates" value="true"/>
</property>

Copyright © 1997, 2012 Oracle and/or its affiliates. All rights reserved.

Legal Notices