此内容没有您所选择的语言版本。

6.2.3. Indexed collections


All collection mappings, except those with set and bag semantics, need an index column in the collection table. An index column is a column that maps to an array index, or List index, or Map key. The index of a Map may be of any basic type, mapped with <map-key>. It can be an entity reference mapped with <map-key-many-to-many>, or it can be a composite type mapped with <composite-map-key>. The index of an array or list is always of type integer and is mapped using the <list-index> element. The mapped column contains sequential integers that are numbered from zero by default.
<list-index 
        column="column_name"                 
        base="0|1|..."                       
/>
Copy to Clipboard Toggle word wrap

1

column_name (required): the name of the column holding the collection index values.

2

base (optional - defaults to 0): the 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"/>
Copy to Clipboard Toggle word wrap

1

column (optional): the name of the column holding the collection index values.

2

formula (optional): a SQL formula used to evaluate the key of the map.

3

type (required): the type of the map keys.
<map-key-many-to-many
        column="column_name"                 
        formula="any SQL expression"         
        class="ClassName"                    
/>
Copy to Clipboard Toggle word wrap

1

column (optional): the name of the foreign key column for the collection index values.

2

formula (optional): a SQ formula used to evaluate the foreign key of the map key.

3

class (required): the entity class used as the map key.
If your table does not have an index column, and you still wish to use List as the property type, you can map the property as a Hibernate <bag>. A bag does not retain its order when it is persisted to the database, but it can be optionally sorted or ordered when it is retrieved from the database.
返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat