How you add a repository item to a Set, List, Map, or Array depends in part on how you use the cascade attribute. Suppose in the preceding example you had set cascade="update" in the books_written property:

<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 then 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 will have to add the item using 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 would be most efficient to ensure that all of these method calls are performed in a single transaction. See Repositories and Transactions in the SQL Repository Architecture section.

 
loading table of contents...