Collection (attribute of param)

From JRapid

Jump to: navigation, search

The "collection" attribute enables a property to contain more than one value.

Collections allow you to create many-to-one or many-to-many relationships between entities.

Type of collections:

  • set: collection that contains no duplicated items.
  • sortedset: a set which comes already sorted from the database.
  • list: simple collection of items, permits all elemements, including null.

Usage

<property 
                ...
                collection = "set | list | sortedset"
                embedded = "inline | detail | grid"
                extendable = "extendable"
                ...
/>

Example

  • Many-to-many relationships:

The following "Industry" entity represents the different types of industries in which a "Company" can perform:

 <entity label="Industry" menu="Company" name="Industry">
        <property display="primary" label="Industry Name" name="name"/>
 </entity>

If a company can perform in several Industries, the following definition for the "Company" entity won't work for such a requirement as it specifies that a company performs in only one industry:

 <entity label="Company" name="Company">
            ...
            <property entity="Industry" label="Industry" name="industry"/> 
            ...
 </entity>

The "Company" entity should specify an "industries" property of type "collection".

 <entity label="Company" name="Company">
            ...
            <property collection="set" entity="Industry" label="Industries" name="industries"/>
            ...
 </entity>

In this case, a many-to-many relationship is created. This means that many companies can perform in many industries.

  • One-to-many relationships:

One-to-many relationships are created when the childproperty attribute is specified in the property of type "collection", this attribute connects entities. The "childproperty" atrribute can be defined only when the collection is embedded.

 <entity label="Company" name="Company">
       ...
       <property embedded="inline" childproperty="company" collection="set" entity="Employee" label="Employees"
       name="employees"/>
       ...
 </entity> 
 <entity label="Employee" name="Employee">
       ...
       <property entity="Company" label="Company" name="company" />
       ...
 </entity>

The result of the above code will be a one-to-many relationship from Company to Employee. One Company can have many Employees and each employee can belong only to one Company.

You can check the Hibernate Mapping Files (.hbm) to ensure you are creating the correct relationships between entities.

See also

Personal tools