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.


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.

        formula="any SQL expression"        

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.

        formula="any SQL expression"        

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:
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on 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!