Hibernate operations on collection properties

Hibernate's operation on collection attributes: For entities, collection attributes are loaded in a delayed manner, which means that when an entity is found, the collection elements are not queried, but only when the collection elements are obtained, the query is performed.

 

1. Set collection attribute operation

1. Set collection mapping configuration, use of set collection attributes

In the Student instance class, add Set<String> hobby and use it in the mapping file

<set> element: create a separate table

<set name="hobby" table = "hobby_set">

<key column = "student_id"></key>

<element type = "string" column = "hobby"/>

</set> 

 

2. List set mapping configuration, use of list set attributes

<list name="hobby" table = "hobby_list">

<key column = "student_id"></key>

<list-index column="position"></list-index>

<element type = "string" column = "hobby"/>

</list >

 

3. Collection collection

<bag name="hobby" table="hobby_tab_c">

<key column = "student_id"></key>

<element type = "string" column = "hobby"/>

</bag>

 

<idbag> does not want <bag> to delete records first and then insert records, so the performance is better than <bag> 

<idbag name="hobby" table="hobby_tab_c">

<key column = "student_id"></key>

<element type = "string" column = "hobby"/>

<collection-id type="string" column="hobby_id">

<generator class = "uuid"></generator>

</collection-id>

</idbag>

 

4. Map collection attribute operation

<map name="hobby" table = "stu_map_hobby">

<key column = "student_id"></key>

<map-key column = "map-key" type = "string">

<element type= "string" column = "hobby">

</map>

 

 

 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326573261&siteId=291194637