Hibernate Reference Documentation, 2010.pdf
(
2152 KB
)
Pobierz
HIBERNATE - Relational
Persistence for Idiomatic Java
1
Hibernate Reference
Documentation
3.6.10.Final
by Gavin King, Christian Bauer, Max Rydahl Andersen,
Emmanuel Bernard, Steve Ebersole, and Hardy Ferentschik
and thanks to James Cobb (Graphic Design) and Cheyenne Weaver (Graphic Design)
Preface .............................................................................................................................
1. Tutorial
........................................................................................................................
1.1. Part 1 - The first Hibernate Application ................................................................
1.1.1. Setup ......................................................................................................
1.1.2. The first class ..........................................................................................
1.1.3. The mapping file ......................................................................................
xi
1
1
1
3
4
1.1.4. Hibernate configuration ............................................................................. 7
1.1.5. Building with Maven ................................................................................. 9
1.1.6. Startup and helpers .................................................................................. 9
1.1.7. Loading and storing objects .................................................................... 10
1.2. Part 2 - Mapping associations ........................................................................... 13
1.2.1. Mapping the Person class ...................................................................... 13
1.2.2. A unidirectional Set-based association ..................................................... 14
1.2.3. Working the association .......................................................................... 15
1.2.4. Collection of values ................................................................................ 17
1.2.5. Bi-directional associations ....................................................................... 19
1.2.6. Working bi-directional links ..................................................................... 19
1.3. Part 3 - The EventManager web application ....................................................... 20
1.3.1. Writing the basic servlet .........................................................................
1.3.2. Processing and rendering .......................................................................
1.3.3. Deploying and testing .............................................................................
1.4. Summary ..........................................................................................................
2. Architecture
...............................................................................................................
2.1. Overview ..........................................................................................................
2.1.1. Minimal architecture ...............................................................................
2.1.2. Comprehensive architecture ....................................................................
2.1.3. Basic APIs .............................................................................................
2.2. JMX Integration ................................................................................................
2.3. Contextual sessions ..........................................................................................
3. Configuration
.............................................................................................................
3.1. Programmatic configuration ...............................................................................
3.2. Obtaining a SessionFactory ...............................................................................
3.3. JDBC connections ............................................................................................
3.4. Optional configuration properties ........................................................................
3.4.1. SQL Dialects ..........................................................................................
3.4.2. Outer Join Fetching ................................................................................
3.4.3. Binary Streams ......................................................................................
3.4.4. Second-level and query cache ................................................................
3.4.5. Query Language Substitution ..................................................................
3.4.6. Hibernate statistics .................................................................................
3.5. Logging ............................................................................................................
3.6. Implementing a NamingStrategy ........................................................................
3.7. Implementing a PersisterClassProvider ..............................................................
3.8. XML configuration file ........................................................................................
20
22
23
24
25
25
25
26
27
28
28
31
31
32
32
34
42
43
43
43
43
44
44
45
45
46
iii
HIBERNATE - Relational Persis...
3.9. Java EE Application Server integration ...............................................................
3.9.1. Transaction strategy configuration ...........................................................
3.9.2. JNDI-bound SessionFactory ....................................................................
3.9.3. Current Session context management with JTA ........................................
3.9.4. JMX deployment ....................................................................................
4. Persistent Classes
.....................................................................................................
4.1. A simple POJO example ...................................................................................
4.1.1. Implement a no-argument constructor ......................................................
4.1.2. Provide an identifier property ..................................................................
4.1.3. Prefer non-final classes (semi-optional) ...................................................
4.1.4. Declare accessors and mutators for persistent fields (optional) ..................
47
47
49
49
50
53
53
54
55
55
56
4.2. Implementing inheritance ................................................................................... 56
4.3. Implementing equals() and hashCode() .............................................................. 57
4.4. Dynamic models ............................................................................................... 58
4.5. Tuplizers .......................................................................................................... 60
4.6. EntityNameResolvers ........................................................................................ 61
5. Basic O/R Mapping
.................................................................................................... 65
5.1. Mapping declaration .......................................................................................... 65
5.1.1. Entity ..................................................................................................... 68
5.1.2. Identifiers ............................................................................................... 73
5.1.3. Optimistic locking properties (optional) ..................................................... 91
5.1.4. Property ................................................................................................. 94
5.1.5. Embedded objects (aka components) .................................................... 103
5.1.6. Inheritance strategy .............................................................................. 106
5.1.7. Mapping one to one and one to many associations ................................. 117
5.1.8. Natural-id ............................................................................................. 126
5.1.9. Any ...................................................................................................... 127
5.1.10. Properties .......................................................................................... 129
5.1.11. Some hbm.xml specificities ................................................................. 130
5.2. Hibernate types ............................................................................................... 134
5.2.1. Entities and values ............................................................................... 134
5.2.2. Basic value types ................................................................................. 135
5.2.3. Custom value types .............................................................................. 137
5.3. Mapping a class more than once ..................................................................... 138
5.4. SQL quoted identifiers ..................................................................................... 139
5.5. Generated properties ....................................................................................... 139
5.6. Column transformers: read and write expressions ............................................. 140
5.7. Auxiliary database objects ............................................................................... 141
6. Types
....................................................................................................................... 143
6.1. Value types .................................................................................................... 143
6.1.1. Basic value types ................................................................................. 143
6.1.2. Composite types .................................................................................. 149
6.1.3. Collection types .................................................................................... 149
6.2. Entity types ..................................................................................................... 150
iv
6.3. Significance of type categories .........................................................................
6.4. Custom types ..................................................................................................
6.4.1. Custom types using org.hibernate.type.Type ..........................................
6.4.2. Custom types using org.hibernate.usertype.UserType .............................
6.4.3. Custom types using org.hibernate.usertype.CompositeUserType .............
6.5. Type registry ...................................................................................................
7. Collection mapping
..................................................................................................
7.1. Persistent collections .......................................................................................
7.2. How to map collections ...................................................................................
7.2.1. Collection foreign keys ..........................................................................
7.2.2. Indexed collections ...............................................................................
150
150
150
152
153
155
157
157
158
162
162
7.2.3. Collections of basic types and embeddable objects ................................. 168
7.3. Advanced collection mappings ......................................................................... 170
7.3.1. Sorted collections ................................................................................. 170
7.3.2. Bidirectional associations ...................................................................... 171
7.3.3. Bidirectional associations with indexed collections .................................. 176
7.3.4. Ternary associations ............................................................................. 177
7.3.5. Using an <idbag> ................................................................................. 178
7.4. Collection examples ........................................................................................
8. Association Mappings
.............................................................................................
8.1. Introduction .....................................................................................................
8.2. Unidirectional associations ...............................................................................
8.2.1. Many-to-one .........................................................................................
8.2.2. One-to-one ...........................................................................................
8.2.3. One-to-many ........................................................................................
8.3. Unidirectional associations with join tables ........................................................
8.3.1. One-to-many ........................................................................................
8.3.2. Many-to-one .........................................................................................
8.3.3. One-to-one ...........................................................................................
8.3.4. Many-to-many ......................................................................................
8.4. Bidirectional associations .................................................................................
8.4.1. one-to-many / many-to-one ...................................................................
8.4.2. One-to-one ...........................................................................................
8.5. Bidirectional associations with join tables ..........................................................
8.5.1. one-to-many / many-to-one ...................................................................
8.5.2. one to one ...........................................................................................
8.5.3. Many-to-many ......................................................................................
8.6. More complex association mappings ................................................................
9. Component Mapping
................................................................................................
9.1. Dependent objects ..........................................................................................
9.2. Collections of dependent objects ......................................................................
9.3. Components as Map indices ............................................................................
9.4. Components as composite identifiers ...............................................................
9.5. Dynamic components ......................................................................................
179
185
185
185
185
185
186
187
187
188
188
189
190
190
191
192
192
193
193
194
197
197
199
200
200
202
v
Plik z chomika:
Ryjufka
Inne pliki z tego folderu:
Beginning Hibernate, 2nd Edition, 2010.pdf
(9815 KB)
Beginning Hibernate, 2006.pdf
(2540 KB)
Beginning Hibernate, 3rd Edition, 2014.pdf
(2563 KB)
Guide to Java Persistence and Hibernate.pdf
(2327 KB)
Hibernate Reference Documentation, 2010.pdf
(2152 KB)
Inne foldery tego chomika:
Advanced Topics
Ant
Application Servers
Certification Guides
Data Structures
Zgłoś jeśli
naruszono regulamin