You can also specify that a repository item property is a collection of repository items. In the previous example, an author may have written more than one book. Instead of the book
property in the preceding example, this next example uses a books_written
property whose value is a Set
of book
repository items. The <property>
tag for the books_written
property uses the following attributes:
data-type="set"
, to specify that the property value is aSet
of itemscomponent-item-type="book"
, to specify that the items making up the set are items of thebook
item descriptorcolumn-name="book_id"
, to specify that the database column is namedbook_id
, rather thanbooks_written
.
<!-- The "book" item type --> <item-descriptor name="book" default="true"> <table name="book" type="primary" id-column-names="book_id"> <property name="title"/> <property name="author" item-type="author" column-name="author_id"/> </table> </item-descriptor> <!-- The "author" item type --> <item-descriptor name="author"> <table name="author" id-column-names="author_id" type="primary"> <property name="lastName"/> <property name="city"/> <property name="state"/> <property name="zip"/> </table> <table name="book" id-column-names="author_id" type="multi"> <property name="books_written" data-type="set" component-item-type="book" column-name="book_id"/> </table> </item-descriptor>
In this example, the book
table is defined twice in the XML, first in the book
item descriptor and in the author
item descriptor. The second time, this table is a multi-table where each author
item can have more than one row with the id
column. In a multi-table, all defined attributes are multi-valued types. To define Array
, List
and Map
types, you also must specify a multi-column-name
attribute on the table tag. This specifies which column to use as the sorting value in order to determine the order of the List
and the key for the Map
.
Now the properties author
and books_written
are actually real beans (in this case RepositoryItems) instead of just simple Java primitives. In the author
item descriptor, the books_written
property is a Set
of RepositoryItems that correspond to books. The other types supported are List
, Map
, and Array
.