Indexed collections by R4R Team

Indexed collections: We can determine to the collection element in two parts that is:

1. Indexed
2. Non-indexed

In the collection elements List and Map collection are indexed whereas set and bag collection are non-indexed. In the indexed collection means List and Map requires an additional element <index>.

Except to those with set and bag semmantics in all collection mapping, need and index column in the collection table. An index column is a column that map to an array index, or List index, or Map key. We can say that an index of Map may be of any basic type, mapped with <map-key>. In can be work as an entity referces mapped with <map-key-many>, or it can be composite type mapped with <composite-map-key>. The index of an array or list is always of the type integer and it mapped using the <list-index> element. The mapped column contains sequential integers that are numbered from zero to by default.

<list-index 
        column="column_name"                
        base="0|1|..."
/>

Description of the above code:

1.column_name (required): Name of column holding the collection index values.
2.base (optional - defaults to 0): Value of the index column that corresponds to the first element of the list or array.

<map-key 
        column="column_name"                
        formula="any SQL expression"        
        type="type_name"                    
        node="@attribute-name"
        length="N"
/>

Descripton of the above code:

1.column (optional): Name of the column holding the collection index values.
2.formula (optional):SQL formula used to evaluate the key of the map.
3.type (required):Type of the map keys.

<map-key-many-to-many
        column="column_name"                
        formula="any SQL expression"        
        class="ClassName"
/>

Description of the above code:

1.column (optional):Name of the foreign key column for the collection index values.
2.formula (optional):SQL formula used to evaluate the foreign key of the map key.
3.class (required): Entity class used as the map key.

With the help of the above code we can understand that if table does not have and index column, then still with to use List as the property type, so then we can map with the hibernate tag as <bag>. A bag does not retain its order when it is retrieved from the database, but it can be optionally sorted or ordered.
Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!