1
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2
+ <!--
3
+ ~ Hibernate, Relational Persistence for Idiomatic Java
4
+ ~
5
+ ~ License: GNU Lesser General Public License (LGPL), version 2.1 or later.
6
+ ~ See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
7
+ -->
8
+ <chapter xml : id =" collections"
9
+ version =" 5.0"
10
+ xml : lang =" en"
11
+ xmlns =" http://docbook.org/ns/docbook"
12
+ xmlns : xi =" http://www.w3.org/2001/XInclude"
13
+ >
14
+ <title >Collections</title >
15
+
16
+ <section xml : id =" collections-synopsis" >
17
+ <title >Collections as a value type</title >
18
+ <para >
19
+ discussions of what it means for them to be value types - lifecycle, opt-locking
20
+ </para >
21
+ <para >
22
+ Collections have the usual behavior of value types. They are automatically persisted when referenced by
23
+ a persistent object and are automatically deleted when unreferenced. If a collection is passed from one
24
+ persistent object to another, its elements might be moved from one table to another. Two entities cannot
25
+ share a reference to the same collection instance.
26
+ </para >
27
+ <para >
28
+ Collection attributes do not support null value semantics; Hibernate does not distinguish between a null
29
+ collection reference and an empty collection.
30
+ </para >
31
+ <para >
32
+ It is important that collections be defined using the appropriate Java Collections Framework interface
33
+ rather than a specific implementation. From a theoretical perspective, this just follows good design
34
+ principles. From a practical perspective, Hibernate (really all persistence providers) will use
35
+ their own collection implementations which conform to the Java Collections Framework interfaces.
36
+ </para >
37
+ </section >
38
+
39
+ <section xml : id =" collections-value" >
40
+ <title >Collections of value types</title >
41
+ <para >
42
+ collection of values - elements can be of any value type except for collections (in fact even compositions as the element cannot contain collections)
43
+ * basics
44
+ * compositions
45
+ </para >
46
+ </section >
47
+
48
+ <section xml : id =" collections-entity" >
49
+ <title >Collections of entities</title >
50
+ <para >
51
+ * one-to-many
52
+ * many-to-many
53
+ </para >
54
+ </section >
55
+
56
+ <section xml : id =" collections-list" >
57
+ <title >List - index</title >
58
+ <para >
59
+ <!-- todo : discuss mapping list index -->
60
+ todo : discuss mapping list index
61
+ </para >
62
+ </section >
63
+
64
+ <section xml : id =" collections-map" >
65
+ <title >Map - key</title >
66
+ <para >
67
+ <!-- todo : discuss mapping map key -->
68
+ todo : discuss mapping map key
69
+ </para >
70
+ </section >
71
+
72
+ <section xml : id =" collections-bag" >
73
+ <title >Bags</title >
74
+ <para >
75
+ <!-- todo : discuss mapping bags -->
76
+ todo : discuss mapping bags
77
+ </para >
78
+ </section >
79
+
80
+ <section xml : id =" collections-array" >
81
+ <title >Arrays</title >
82
+ <para >
83
+ <!-- todo : discuss mapping arrays -->
84
+ todo : discuss mapping arrays
85
+ </para >
86
+ </section >
87
+
88
+ <section xml : id =" collections-as-basic" >
89
+ <title >Collections as basic value type</title >
90
+ <para >
91
+ Notice how all the previous examples explicitly mark the collection attribute as either
92
+ ElementCollection, OneToMany or ManyToMany. Collections not marked as such, or collections explicitly
93
+ maked with @Basic are treated as JPA basic value. Meaning there value is stored into a single
94
+ column in the containing table.
95
+ </para >
96
+ <para >
97
+ This is sometimes beneficial. Consider a use-case such as a VARCHAR column that represents a
98
+ delimited list or set of Strings.
99
+ </para >
100
+ <example >
101
+ <title >Delimited set of tags</title >
102
+ <programlisting role =" JAVA" ><xi : include href =" extras/DelimitedStringTagsExample.java" parse =" text" /></programlisting >
103
+ </example >
104
+
105
+ <para >
106
+ See the <citetitle >Hibernate Integrations Guide</citetitle > for more details on developing
107
+ custom value type mappings.
108
+ </para >
109
+ </section >
110
+
111
+ </chapter >
0 commit comments