| |
Inhaltsverzeichnis |
6 |
|
| |
Kapitel 1 – Einleitung |
14 |
|
| |
1.1 Impedance Mismatch |
14 |
|
| |
1.1.1 Granularität |
14 |
|
| |
1.1.2 Vererbung |
15 |
|
| |
1.1.3 Objektidentität |
15 |
|
| |
1.1.4 Beziehungen |
15 |
|
| |
1.1.5 Graphennavigation |
16 |
|
| |
1.2 Hibernate |
16 |
|
| |
1.3 Java Persistence API |
17 |
|
| |
1.4 Aufbau des Buches |
17 |
|
| |
1.5 Webseite zum Buch |
18 |
|
| |
1.6 Danksagung |
18 |
|
| |
Kapitel 2 – Hibernate, Java 5 und die Java Persistence API |
20 |
|
| |
2.1 Java 5 |
20 |
|
| |
2.1.1 Annotations |
20 |
|
| |
2.1.2 Generics |
23 |
|
| |
2.2 EJB 3.0 - Java Persistence API |
26 |
|
| |
2.2.1 Die Java Persistence API |
26 |
|
| |
2.2.2 Entities |
26 |
|
| |
2.2.3 Entity Manager |
32 |
|
| |
2.2.4 Entity Listener und Callback-Methoden |
35 |
|
| |
2.2.5 Query API und die EJB QL |
37 |
|
| |
2.3 Hibernate Annotations |
38 |
|
| |
2.3.1 Hibernate Validator |
39 |
|
| |
2.4 Hibernate EntityManager |
41 |
|
| |
2.5 Zusammenfassung |
42 |
|
| |
Kapitel 3 – Einführung in Hibernate |
44 |
|
| |
3.1 Beispielprojekt |
44 |
|
| |
3.1.1 Die Anwendungsfälle |
44 |
|
| |
3.1.2 Das Klassendiagramm |
45 |
|
| |
3.2 Erste Schritte |
45 |
|
| |
3.2.1 Sichern |
52 |
|
| |
3.2.2 Laden |
55 |
|
| |
3.2.3 Aktualisieren |
56 |
|
| |
3.2.4 Hibernate XML-Mapping |
57 |
|
| |
3.3 Generatorstrategien |
58 |
|
| |
3.4 Architektur |
62 |
|
| |
3.4.1 Überblick |
62 |
|
| |
3.4.2 Schnittstellen |
63 |
|
| |
3.5 Zusammenfassung |
64 |
|
| |
Kapitel 4 – Lebenszyklus einer Hibernate Entity |
66 |
|
| |
4.1 Die Zustände einer Hibernate Entity |
66 |
|
| |
4.1.1 Transient |
67 |
|
| |
4.1.2 Persistent |
67 |
|
| |
4.1.3 Detached |
68 |
|
| |
4.2 Verwendung von Detached Hibernate Entities |
69 |
|
| |
4.2.1 Verwendung von update(...) und merge(...) |
70 |
|
| |
4.2.2 Optimistisches Locking mit Hibernate |
71 |
|
| |
4.2.3 Lazy Loading und Detached Entities |
72 |
|
| |
4.3 Zusammenfassung |
74 |
|
| |
Kapitel 5 – Komponenten, Assoziationen und Vererbung |
76 |
|
| |
5.1 Komponenten |
76 |
|
| |
5.2 Assoziationen |
80 |
|
| |
5.2.1 1-zu-1-Beziehungen |
80 |
|
| |
5.2.2 1-zu-n- und n-zu-1-Beziehungen |
85 |
|
| |
5.2.3 N-zu-m-Beziehungen |
90 |
|
| |
5.2.4 Transitive Persistenz |
91 |
|
| |
5.3 Vererbung |
94 |
|
| |
5.3.1 SINGLE_TABLE |
95 |
|
| |
5.3.2 TABLE_PER_CLASS |
98 |
|
| |
5.3.3 JOINED |
100 |
|
| |
5.4 Zusammenfassung |
101 |
|
| |
Kapitel 6 – Collections in Hibernate |
102 |
|
| |
6.1 Persistente Collections |
102 |
|
| |
6.2 Collection Mapping |
103 |
|
| |
6.3 Collections mit Index |
106 |
|
| |
6.4 Sortierte Collections |
107 |
|
| |
6.5 Zusammenfassung |
110 |
|
| |
Kapitel 7 – Hibernate Session und Transaktionen |
112 |
|
| |
7.1 Was ist eine Transaktion? |
112 |
|
| |
7.2 Isolationsebenen |
113 |
|
| |
7.3 Transaktionen in Hibernate |
114 |
|
| |
7.4 Optimistisches Locking mit Hibernate |
116 |
|
| |
7.5 Pessimistisches Locking mit Hibernate |
118 |
|
| |
7.6 „Session per Request“-Pattern |
120 |
|
| |
7.7 „Session per Conversation“-Pattern |
121 |
|
| |
7.8 „Open Session in View“-Pattern |
123 |
|
| |
7.9 „Session per Operation“- und „Session per Application“-Antipattern |
125 |
|
| |
7.10 Zusammenfassung |
126 |
|
| |
Kapitel 8 – Datenbankabfragen mit Hibernate |
128 |
|
| |
8.1 Das Query Interface |
128 |
|
| |
8.1.1 Ausführung der Abfragen |
129 |
|
| |
8.1.2 Parameter Binding |
130 |
|
| |
8.1.3 Definition von Abfragen in den Metadaten |
131 |
|
| |
8.2 HQL – die Hibernate Query Language |
132 |
|
| |
8.2.1 Allgemeines |
132 |
|
| |
8.2.2 Der Ausdruck „from“ |
132 |
|
| |
8.2.3 Einschränkung der Ergebnismenge mit „where“ |
133 |
|
| |
8.2.4 Sortierung mit „order by“ |
134 |
|
| |
8.2.5 Joins mit HQL |
134 |
|
| |
8.2.6 Die „select“-Anweisung |
136 |
|
| |
8.2.7 Aggregat-Funktionen in HQL |
137 |
|
| |
8.2.8 Die „group by“-Anweisung |
138 |
|
| |
8.2.9 Polymorphe Abfragen |
138 |
|
| |
8.2.10 Subqueries |
139 |
|
| |
8.3 Criteria API |
139 |
|
| |
8.3.1 Ausführung der Abfragen |
139 |
|
| |
8.3.2 Einschränkung der Ergebnismenge mit Restrictions |
140 |
|
| |
8.3.3 Sortierung mit org.hibernate.criterion.Order |
143 |
|
| |
8.3.4 Assoziationen |
144 |
|
| |
8.3.5 Abfragen mit org.hibernate.criterion.Example |
145 |
|
| |
8.3.6 Die Klasse org.hibernate.criterion.DetachedCriteria |
145 |
|
| |
8.4 Native SQL |
146 |
|
| |
8.5 Hibernate Filter |
148 |
|
| |
8.6 Zusammenfassung |
149 |
|
| |
Kapitel 9 – Hibernate Types |
150 |
|
| |
9.1 Hibernate Mapping Types |
150 |
|
| |
9.2 Benutzerdefinierte Mapping Types |
152 |
|
| |
9.3 Zusammenfassung |
159 |
|
| |
Kapitel 10 – Fetching-Strategien und Caches |
160 |
|
| |
10.1 Fetching-Strategien |
160 |
|
| |
10.1.1 Das N + 1-Problem |
162 |
|
| |
10.1.2 Batch-Fetching |
163 |
|
| |
10.1.3 Join-Fetching |
164 |
|
| |
10.1.4 Subselect-Fetching |
165 |
|
| |
10.2 Hibernate Query Cache |
166 |
|
| |
10.3 Second Level Cache |
166 |
|
| |
10.3.1 Strategien und Konfiguration |
166 |
|
| |
10.3.2 Second Level Cache Provider |
168 |
|
| |
10.4 Massen-Update und -Delete |
168 |
|
| |
10.5 Zusammenfassung |
169 |
|
| |
Kapitel 11 – Webanwendungen mit Java Persistence API und Spring |
170 |
|
| |
11.1 Das Spring Framework |
170 |
|
| |
11.1.1 Dependency Injection |
170 |
|
| |
11.1.2 Spring AOP |
172 |
|
| |
11.1.3 Springs Java Persistence API Support |
174 |
|
| |
11.1.4 Spring MVC |
174 |
|
| |
11.2 Die Beispielanwendung |
179 |
|
| |
11.2.1 Datenschicht |
180 |
|
| |
11.2.2 Serviceschicht |
185 |
|
| |
11.2.3 Transaktionen |
187 |
|
| |
11.2.4 Präsentationsschicht |
189 |
|
| |
11.3 Deployment |
196 |
|
| |
11.4 Zusammenfassung |
196 |
|
| |
Kapitel 12 – Entwicklungsprozess und Tools |
198 |
|
| |
12.1 Hibernate Tools |
198 |
|
| |
12.1.1 Integration mit Ant |
198 |
|
| |
12.1.2 Einrichten des Tasks |
198 |
|
| |
12.1.3 Konfiguration des Tasks |
200 |
|
| |
12.1.4 Generieren von Quelldateien |
201 |
|
| |
12.1.5 Generieren des Datenbankschemas |
201 |
|
| |
12.1.6 Generieren von Mapping-Dateien |
203 |
|
| |
12.2 Entwicklungsprozess |
203 |
|
| |
12.2.1 Top-Down |
203 |
|
| |
12.2.2 Bottom-Up |
204 |
|
| |
12.2.3 Middle-Out |
204 |
|
| |
12.2.4 Meet-in-the-Middle |
205 |
|
| |
12.3 Integration in Eclipse |
205 |
|
| |
12.3.1 Installation der Plugins |
205 |
|
| |
12.3.2 Die Hibernate Console |
206 |
|
| |
12.3.3 Entwicklungsprozess mit Eclipse |
206 |
|
| |
12.4 Modellgetrieben mit AndroMDA |
206 |
|
| |
12.4.1 Was heißt „Modellgetrieben“? |
206 |
|
| |
12.4.2 AndroMDA |
208 |
|
| |
12.5 Zusammenfassung |
209 |
|
| |
Anhang A – Referenz der Annotationen |
210 |
|
| |
A.1 Metadata-Annotationen |
210 |
|
| |
A.1.1 Entity |
210 |
|
| |
A.2 Callback-Annotationen |
210 |
|
| |
A.2.1 EntityListeners |
210 |
|
| |
A.2.2 ExcludeSuperclassListeners |
211 |
|
| |
A.2.3 ExcludeDefaultListeners |
211 |
|
| |
A.2.4 PrePersist |
211 |
|
| |
A.2.5 PostPersist |
212 |
|
| |
A.2.6 PreRemove |
212 |
|
| |
A.2.7 PostRemove |
213 |
|
| |
A.2.8 PreUpdate |
213 |
|
| |
A.2.9 PostUpdate |
213 |
|
| |
A.2.10 PostLoad |
214 |
|
| |
A.3 Annotationen für Datenbankabfragen |
214 |
|
| |
A.3.1 NamedQuery |
214 |
|
| |
A.3.2 QueryHint |
215 |
|
| |
A.3.3 NamedQueries |
215 |
|
| |
A.3.4 NamedNativeQuery |
216 |
|
| |
A.3.5 NamedNativeQueries |
216 |
|
| |
A.4 Abbilden der SQL Abfrageergebnisse |
217 |
|
| |
A.4.1 SQLResultSetMapping |
217 |
|
| |
A.4.2 SQLResultSetMappings |
217 |
|
| |
A.4.3 EntityResult |
218 |
|
| |
A.4.4 FieldResult |
218 |
|
| |
A.4.5 ColumnResult |
219 |
|
| |
A.5 Referenzen auf den EntityManager und die EntityManagerFactory |
219 |
|
| |
A.5.1 PersistenceContext |
219 |
|
| |
A.5.2 PersistenceProperty |
220 |
|
| |
A.5.3 PersistenceContexts |
220 |
|
| |
A.5.4 PersistenceUnit |
221 |
|
| |
A.5.5 PersistenceUnits |
221 |
|
| |
A.6 Annotationen für die Definition der Abbildungen der Entitäten |
222 |
|
| |
A.6.1 Table |
222 |
|
| |
A.6.2 UniqueConstraint |
222 |
|
| |
A.6.3 SecondaryTable |
223 |
|
| |
A.7 Definieren von Primärschlüsseln |
224 |
|
| |
A.7.1 Id |
224 |
|
| |
A.7.2 GeneratedValue |
224 |
|
| |
A.7.3 EmbeddedId |
225 |
|
| |
A.7.4 IdClass |
225 |
|
| |
A.7.5 SequenceGenerator |
225 |
|
| |
A.7.6 TableGenerator |
226 |
|
| |
A.8 Annotationen zum Überschreiben bestehender Abbildungen |
227 |
|
| |
A.8.1 AttributeOverride |
227 |
|
| |
A.8.2 AttributeOverrides |
227 |
|
| |
A.8.3 AssociationOverride |
228 |
|
| |
A.8.4 AssociationOverrides |
228 |
|
| |
A.9 Annotationen für Entitätseigenschaften |
229 |
|
| |
A.9.1 Transient |
229 |
|
| |
A.9.2 Column |
229 |
|
| |
A.9.3 Basic |
230 |
|
| |
A.9.4 Lob |
230 |
|
| |
A.9.5 Temporal |
231 |
|
| |
A.9.6 Enumerated |
231 |
|
| |
A.9.7 Version |
232 |
|
| |
A.10 Annotationen für Assoziationen |
232 |
|
| |
A.10.1 JoinColumn |
232 |
|
| |
A.10.2 JoinColumns |
233 |
|
| |
A.10.3 ManyToOne |
233 |
|
| |
A.10.4 OneToOne |
234 |
|
| |
A.10.5 OneToMany |
235 |
|
| |
A.10.6 ManyToMany |
236 |
|
| |
A.10.7 JoinTable |
236 |
|
| |
A.10.8 MapKey |
237 |
|
| |
A.10.9 OrderBy |
237 |
|
| |
A.10.10 PrimaryKeyJoinColumn |
238 |
|
| |
A.10.11 PrimaryKeyJoinColumns |
238 |
|
| |
A.11 Annotationen für Vererbung |
239 |
|
| |
A.11.1 DiscriminatorColumn |
239 |
|
| |
A.11.2 DiscriminatorValue |
240 |
|
| |
A.11.3 MappedSuperclass |
240 |
|
| |
A.12 Annotationen für eingebettete Komponenten |
241 |
|
| |
A.12.1 Embeddable |
241 |
|
| |
A.12.2 Embedded |
241 |
|
| |
A.13 Hibernate-spezifische Annotationen |
242 |
|
| |
A.13.1 Entity |
242 |
|
| |
A.13.2 Table |
243 |
|
| |
A.13.3 Index |
243 |
|
| |
A.13.4 Tables |
244 |
|
| |
A.13.5 Proxy |
244 |
|
| |
A.13.6 AccessType |
245 |
|
| |
A.13.7 BatchSize |
245 |
|
| |
A.13.8 Cache |
245 |
|
| |
A.13.9 Cascade |
246 |
|
| |
A.13.10 Check |
247 |
|
| |
A.13.11 CollectionOfElements |
247 |
|
| |
A.13.12 Columns |
248 |
|
| |
A.13.13 DiscriminatorFormula |
248 |
|
| |
A.13.14 Fetch |
248 |
|
| |
A.13.15 Filter |
249 |
|
| |
A.13.16 Filters |
249 |
|
| |
A.13.17 FilterDef |
250 |
|
| |
A.13.18 ParamDef |
250 |
|
| |
A.13.19 FilterDefs |
251 |
|
| |
A.13.20 Formula |
251 |
|
| |
A.13.21 Generated |
252 |
|
| |
A.13.22 GenericGenerator |
252 |
|
| |
A.13.23 Parameter |
253 |
|
| |
A.13.24 IndexColumn |
253 |
|
| |
A.13.25 LazyCollection |
254 |
|
| |
A.13.26 LazyToOne |
254 |
|
| |
A.13.27 MapKey |
255 |
|
| |
A.13.28 MapKeyManyToMany |
255 |
|
| |
A.13.29 NamedNativeQuery |
255 |
|
| |
A.13.30 NamedNativeQueries |
256 |
|
| |
A.13.31 NamedQuery |
257 |
|
| |
A.13.32 NamedQueries |
258 |
|
| |
A.13.33 NotFound |
258 |
|
| |
A.13.34 OnDelete |
259 |
|
| |
A.13.35 OrderBy |
259 |
|
| |
A.13.36 Parent |
260 |
|
| |
A.13.37 Sort |
260 |
|
| |
A.13.38 Type |
261 |
|
| |
A.13.39 TypeDef |
261 |
|
| |
A.13.40 TypeDefs |
262 |
|
| |
A.13.41 Where |
262 |
|
| |
Anhang B – Literaturverzeichnis |
264 |
|
| |
Stichwortverzeichnis |
266 |
|