/
Data_Categorizations.xml
452 lines (433 loc) · 18.5 KB
/
Data_Categorizations.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
<?xml version='1.0' encoding='utf-8' ?>
<chapter xmlns="http://docbook.org/ns/docbook">
<title>Data categorizations</title>
<para>
Hibernate understands both the Java and JDBC representations of application data. The ability to read and write
object data to a database is called <firstterm>marshalling</firstterm>, and is the function of a Hibernate
<classname>type</classname>. A <classname>type</classname> is an implementation of the
<interfacename>org.hibernate.type.Type</interfacename> interface. A Hibernate <classname>type</classname> describes
various aspects of behavior of the Java type such as how to check for equality and how to clone values.
</para>
<note>
<title>Usage of the word <wordasword>type</wordasword></title>
<para>
A Hibernate <classname>type</classname> is neither a Java type nor a SQL datatype. It provides information about
both of these.
</para>
<para>
When you encounter the term <firstterm>type</firstterm> in regards to Hibernate, it may refer to the Java type,
the JDBC type, or the Hibernate type, depending on context.
</para>
</note>
<para>
Hibernate categorizes types into two high-level groups: <xref linkend="value-types" />
and <xref linkend="entity-types" />.
</para>
<section xml:id="value-types">
<title>Value types</title>
<para>
A <firstterm>value type</firstterm> does not define its own lifecycle. It is, in effect, owned by an <xref
linkend="entity-types" />, which defines its
lifecycle. Value types are further classified into three sub-categories.
</para>
<itemizedlist>
<listitem><para><xref linkend="value-basic-types" /></para></listitem>
<listitem><para><xref linkend="value-national-character-types" /></para></listitem>
<listitem><para><xref linkend="value-composite-types" /></para></listitem>
<listitem><para><xref linkend="value-collection-types" /></para></listitem>
</itemizedlist>
<section xml:id="value-basic-types">
<title>Basic types</title>
<para>
Basic value types usually map a single database value, or column, to a single, non-aggregated Java
type. Hibernate provides a number of built-in basic types, which follow the natural mappings recommended in the
JDBC specifications. You can override these mappings and provide and use alternative mappings. These topics are
discussed further on.
</para>
<table>
<title>Basic Type Mappings</title>
<tgroup cols="4">
<thead>
<row>
<entry>Hibernate type</entry>
<entry>Database type</entry>
<entry>JDBC type</entry>
<entry>Type registry</entry>
</row>
</thead>
<tbody>
<row>
<entry>org.hibernate.type.StringType</entry>
<entry>string</entry>
<entry>VARCHAR</entry>
<entry>string, java.lang.String</entry>
</row>
<row>
<entry>org.hibernate.type.MaterializedClob</entry>
<entry>string</entry>
<entry>CLOB</entry>
<entry>materialized_clob</entry>
</row>
<row>
<entry>org.hibernate.type.TextType</entry>
<entry>string</entry>
<entry>LONGVARCHAR</entry>
<entry>text</entry>
</row>
<row>
<entry>org.hibernate.type.CharacterType</entry>
<entry>char, java.lang.Character</entry>
<entry>CHAR</entry>
<entry>char, java.lang.Character</entry>
</row>
<row>
<entry>org.hibernate.type.BooleanType</entry>
<entry>boolean</entry>
<entry>BIT</entry>
<entry>boolean, java.lang.Boolean</entry>
</row>
<row>
<entry>org.hibernate.type.NumericBooleanType</entry>
<entry>boolean</entry>
<entry>INTEGER, 0 is false, 1 is true</entry>
<entry>numeric_boolean</entry>
</row>
<row>
<entry>org.hibernate.type.YesNoType</entry>
<entry>boolean</entry>
<entry>CHAR, 'N'/'n' is false, 'Y'/'y' is true. The uppercase value is written to the database.</entry>
<entry>yes_no</entry>
</row>
<row>
<entry>org.hibernate.type.TrueFalseType</entry>
<entry>boolean</entry>
<entry>CHAR, 'F'/'f' is false, 'T'/'t' is true. The uppercase value is written to the database.</entry>
<entry>true_false</entry>
</row>
<row>
<entry>org.hibernate.type.ByteType</entry>
<entry>byte, java.lang.Byte</entry>
<entry>TINYINT</entry>
<entry>byte, java.lang.Byte</entry>
</row>
<row>
<entry>org.hibernate.type.ShortType</entry>
<entry>short, java.lang.Short</entry>
<entry>SMALLINT</entry>
<entry>short, java.lang.Short</entry>
</row>
<row>
<entry>org.hibernate.type.IntegerTypes</entry>
<entry>int, java.lang.Integer</entry>
<entry>INTEGER</entry>
<entry>int, java.lang.Integer</entry>
</row>
<row>
<entry>org.hibernate.type.LongType</entry>
<entry>long, java.lang.Long</entry>
<entry>BIGINT</entry>
<entry>long, java.lang.Long</entry>
</row>
<row>
<entry>org.hibernate.type.FloatType</entry>
<entry>float, java.lang.Float</entry>
<entry>FLOAT</entry>
<entry>float, java.lang.Float</entry>
</row>
<row>
<entry>org.hibernate.type.DoubleType</entry>
<entry>double, java.lang.Double</entry>
<entry>DOUBLE</entry>
<entry>double, java.lang.Double</entry>
</row>
<row>
<entry>org.hibernate.type.BigIntegerType</entry>
<entry>java.math.BigInteger</entry>
<entry>NUMERIC</entry>
<entry>big_integer</entry>
</row>
<row>
<entry>org.hibernate.type.BigDecimalType</entry>
<entry>java.math.BigDecimal</entry>
<entry>NUMERIC</entry>
<entry>big_decimal, java.math.bigDecimal</entry>
</row>
<row>
<entry>org.hibernate.type.TimestampType</entry>
<entry>java.sql.Timestamp</entry>
<entry>TIMESTAMP</entry>
<entry>timestamp, java.sql.Timestamp</entry>
</row>
<row>
<entry>org.hibernate.type.TimeType</entry>
<entry>java.sql.Time</entry>
<entry>TIME</entry>
<entry>time, java.sql.Time</entry>
</row>
<row>
<entry>org.hibernate.type.DateType</entry>
<entry>java.sql.Date</entry>
<entry>DATE</entry>
<entry>date, java.sql.Date</entry>
</row>
<row>
<entry>org.hibernate.type.CalendarType</entry>
<entry>java.util.Calendar</entry>
<entry>TIMESTAMP</entry>
<entry>calendar, java.util.Calendar</entry>
</row>
<row>
<entry>org.hibernate.type.CalendarDateType</entry>
<entry>java.util.Calendar</entry>
<entry>DATE</entry>
<entry>calendar_date</entry>
</row>
<row>
<entry>org.hibernate.type.CurrencyType</entry>
<entry>java.util.Currency</entry>
<entry>VARCHAR</entry>
<entry>currency, java.util.Currency</entry>
</row>
<row>
<entry>org.hibernate.type.LocaleType</entry>
<entry>java.util.Locale</entry>
<entry>VARCHAR</entry>
<entry>locale, java.utility.locale</entry>
</row>
<row>
<entry>org.hibernate.type.TimeZoneType</entry>
<entry>java.util.TimeZone</entry>
<entry>VARCHAR, using the TimeZone ID</entry>
<entry>timezone, java.util.TimeZone</entry>
</row>
<row>
<entry>org.hibernate.type.UrlType</entry>
<entry>java.net.URL</entry>
<entry>VARCHAR</entry>
<entry>url, java.net.URL</entry>
</row>
<row>
<entry>org.hibernate.type.ClassType</entry>
<entry>java.lang.Class</entry>
<entry>VARCHAR, using the class name</entry>
<entry>class, java.lang.Class</entry>
</row>
<row>
<entry>org.hibernate.type.BlobType</entry>
<entry>java.sql.Blob</entry>
<entry>BLOB</entry>
<entry>blog, java.sql.Blob</entry>
</row>
<row>
<entry>org.hibernate.type.ClobType</entry>
<entry>java.sql.Clob</entry>
<entry>CLOB</entry>
<entry>clob, java.sql.Clob</entry>
</row>
<row>
<entry>org.hibernate.type.BinaryType</entry>
<entry>primitive byte[]</entry>
<entry>VARBINARY</entry>
<entry>binary, byte[]</entry>
</row>
<row>
<entry>org.hibernate.type.MaterializedBlobType</entry>
<entry>primitive byte[]</entry>
<entry>BLOB</entry>
<entry>materized_blob</entry>
</row>
<row>
<entry>org.hibernate.type.ImageType</entry>
<entry>primitive byte[]</entry>
<entry>LONGVARBINARY</entry>
<entry>image</entry>
</row>
<row>
<entry>org.hibernate.type.BinaryType</entry>
<entry>java.lang.Byte[]</entry>
<entry>VARBINARY</entry>
<entry>wrapper-binary</entry>
</row>
<row>
<entry>org.hibernate.type.CharArrayType</entry>
<entry>char[]</entry>
<entry>VARCHAR</entry>
<entry>characters, char[]</entry>
</row>
<row>
<entry>org.hibernate.type.CharacterArrayType</entry>
<entry>java.lang.Character[]</entry>
<entry>VARCHAR</entry>
<entry>wrapper-characters, Character[], java.lang.Character[]</entry>
</row>
<row>
<entry>org.hibernate.type.UUIDBinaryType</entry>
<entry>java.util.UUID</entry>
<entry>BINARY</entry>
<entry>uuid-binary, java.util.UUID</entry>
</row>
<row>
<entry>org.hibernate.type.UUIDCharType</entry>
<entry>java.util.UUID</entry>
<entry>CHAR, can also read VARCHAR</entry>
<entry>uuid-char</entry>
</row>
<row>
<entry>org.hibernate.type.PostgresUUIDType</entry>
<entry>java.util.UUID</entry>
<entry>PostgreSQL UUID, through Types#OTHER, which complies to the PostgreSQL JDBC driver
definition</entry>
<entry>pg-uuid</entry>
</row>
<row>
<entry>org.hibernate.type.SerializableType</entry>
<entry>implementors of java.lang.Serializable</entry>
<entry>VARBINARY</entry>
<entry> Unlike the other value types, multiple instances of this type are registered. It is registered
once under java.io.Serializable, and registered under the specific java.io.Serializable implementation
class names.</entry>
</row>
</tbody>
</tgroup>
</table>
</section>
<section xml:id="value-national-character-types">
<title>National Character Types</title>
<para>
National Character types, which is a new feature since JDBC 4.0 API, now available in hibernate type system.
National Language Support enables you retrieve data or insert data into a database in any character
set that the underlying database supports.
</para>
<para>
Depending on your environment, you might want to set the configuration option <property>hibernate.use_nationalized_character_data</property>
to true and having all string or clob based attributes having this national character support automatically.
There is nothing else to be changed, and you don't have to use any hibernate specific mapping, so it is portable
( though the national character support feature is not required and may not work on other JPA provider impl ).
</para>
<para>
The other way of using this feature is having the <classname>@Nationalized</classname> annotation on the attribute
that should be nationalized. This only works on string based attributes, including string, char, char array and clob.
<programlisting role="JAVA">
@Entity( name="NationalizedEntity")
public static class NationalizedEntity {
@Id
private Integer id;
@Nationalized
private String nvarcharAtt;
@Lob
@Nationalized
private String materializedNclobAtt;
@Lob
@Nationalized
private NClob nclobAtt;
@Nationalized
private Character ncharacterAtt;
@Nationalized
private Character[] ncharArrAtt;
@Type(type = "ntext")
private String nlongvarcharcharAtt;
}</programlisting>
</para>
<table>
<title>National Character Type Mappings</title>
<tgroup cols="4">
<thead>
<row>
<entry>Hibernate type</entry>
<entry>Database type</entry>
<entry>JDBC type</entry>
<entry>Type registry</entry>
</row>
</thead>
<tbody>
<row>
<entry>org.hibernate.type.StringNVarcharType</entry>
<entry>string</entry>
<entry>NVARCHAR</entry>
<entry>nstring</entry>
</row>
<row>
<entry>org.hibernate.type.NTextType</entry>
<entry>string</entry>
<entry>LONGNVARCHAR</entry>
<entry>materialized_clob</entry>
</row>
<row>
<entry>org.hibernate.type.NClobType</entry>
<entry>java.sql.NClob</entry>
<entry>NCLOB</entry>
<entry>nclob</entry>
</row>
<row>
<entry>org.hibernate.type.MaterializedNClobType</entry>
<entry>string</entry>
<entry>NCLOB</entry>
<entry>materialized_nclob</entry>
</row>
<row>
<entry>org.hibernate.type.PrimitiveCharacterArrayNClobType</entry>
<entry>char[]</entry>
<entry>NCHAR</entry>
<entry>char[]</entry>
</row>
<row>
<entry>org.hibernate.type.CharacterNCharType</entry>
<entry>java.lang.Character</entry>
<entry>NCHAR</entry>
<entry>ncharacter</entry>
</row>
<row>
<entry>org.hibernate.type.CharacterArrayNClobType</entry>
<entry>java.lang.Character[]</entry>
<entry>NCLOB</entry>
<entry>Character[], java.lang.Character[]</entry>
</row>
</tbody>
</tgroup>
</table>
</section>
<section xml:id="value-composite-types">
<title>Composite types</title>
<para>
<firstterm>Composite types</firstterm>, or <firstterm>embedded types</firstterm>, as they are called by the Java
Persistence API, have traditionally been called <firstterm>components</firstterm> in Hibernate. All of these
terms mean the same thing.
</para>
<para>
Components represent aggregations of values into a single Java type. An example is an
<classname>Address</classname> class, which aggregates street, city, state, and postal code. A composite type
behaves in a similar way to an entity. They are each classes written specifically for an application. They may
both include references to other application-specific classes, as well as to collections and simple JDK
types. The only distinguishing factors are that a component does not have its own lifecycle or define an
identifier.
</para>
</section>
<section xml:id="value-collection-types">
<title>Collection types</title>
<para>
A <firstterm>collection</firstterm> type refers to the data type itself, not its contents.
</para>
<para>
A Collection denotes a one-to-one or one-to-many relationship between tables of a database.
</para>
<para>
Refer to the chapter on Collections for more information on collections.
</para>
</section>
</section>
<section xml:id="entity-types">
<title>Entity Types</title>
<para>
Entities are application-specific classes which correlate to rows in a table, using a unique identifier. Because
of the requirement for a unique identifier, ntities exist independently and define their own lifecycle. As an
example, deleting a Membership should not delete the User or the Group. For more information, see the chapter on
Persistent Classes.
</para>
</section>
<section>
<title>Implications of different data categorizations</title>
<para>
NEEDS TO BE WRITTEN
</para>
</section>
</chapter>