Hibernate in action

Free Download

Authors:

Edition: illustrated edition

Series: In Action series

ISBN: 9781932394153, 1932394-15-X

Size: 3 MB (3622027 bytes)

Pages: 431/431

File format:

Language:

Publishing Year:

Category:

Christian Bauer, Gavin King9781932394153, 1932394-15-X

ibernate practically exploded on the Java scene. Why is this open-source tool so popular? Because it automates a tedious task: persisting your Java objects to a relational database. The inevitable mismatch between your object-oriented code and the relational database requires you to write code that maps one to the other. This code is often complex, tedious and costly to develop. Hibernate does the mapping for you.
Not only that, Hibernate makes it easy. Positioned as a layer between your application and your database, Hibernate takes care of loading and saving of objects. Hibernate applications are cheaper, more portable, and more resilient to change. And they perform better than anything you are likely to develop yourself.
«Hibernate in Action» carefully explains the concepts you need, then gets you going. It builds on a single example to show you how to use Hibernate in practice, how to deal with concurrency and transactions, how to efficiently retrieve objects and use caching.
The authors created Hibernate and they field questions from the Hibernate community every day-they know how to make Hibernate sing. Knowledge and insight seep out of every pore of this book.
«Whats Inside»
– ORM concepts
– Getting started
– Many real-world tasks
– The Hibernate application development process

Table of contents :
contents……Page 4
foreword……Page 10
preface……Page 12
acknowledgments……Page 14
Roadmap……Page 15
Code conventions and downloads……Page 17
About the authors……Page 18
about Hibernate3 and EJB 3……Page 19
author online……Page 20
About the cover illustration……Page 21
Understanding object/relational persistence……Page 24
1.1.1 Relational databases……Page 26
1.1.2 Understanding SQL……Page 27
1.1.4 Persistence in object-oriented applications……Page 28
1.2 The paradigm mismatch……Page 30
1.2.1 The problem of granularity……Page 32
1.2.2 The problem of subtypes……Page 33
1.2.3 The problem of identity……Page 34
1.2.4 Problems relating to associations……Page 36
1.2.5 The problem of object graph navigation……Page 37
1.2.6 The cost of the mismatch……Page 38
1.3 Persistence layers and alternatives……Page 39
1.3.1 Layered architecture……Page 40
1.3.2 Hand-coding a persistence layer with SQL/JDBC……Page 41
1.3.3 Using serialization……Page 42
1.3.4 Considering EJB entity beans……Page 43
1.3.5 Object-oriented database systems……Page 44
1.4 Object/relational mapping……Page 45
1.4.1 What is ORM?……Page 46
1.4.2 Generic ORM problems……Page 48
1.4.3 Why ORM?……Page 49
1.5 Summary……Page 52
Introducing and integrating Hibernate……Page 53
2.1 “Hello World” with Hibernate……Page 54
2.2 Understanding the architecture……Page 59
2.2.1 The core interfaces……Page 61
2.2.3 Types……Page 63
2.3 Basic configuration……Page 64
2.3.1 Creating a SessionFactory……Page 65
2.3.2 Configuration in non-managed environments……Page 68
2.3.3 Configuration in managed environments……Page 71
2.4.1 Using XML-based configuration……Page 74
2.4.2 JNDI-bound SessionFactory……Page 76
2.4.3 Logging……Page 77
2.4.4 Java Management Extensions (JMX)……Page 78
2.5 Summary……Page 81
Mapping persistent classes……Page 82
3.1 The CaveatEmptor application……Page 83
3.1.2 The CaveatEmptor domain model……Page 84
3.2.1 Addressing leakage of concerns……Page 87
3.2.2 Transparent and automated persistence……Page 88
3.2.3 Writing POJOs……Page 90
3.2.4 Implementing POJO associations……Page 92
3.2.5 Adding logic to accessor methods……Page 96
3.3.1 Metadata in XML……Page 98
3.3.2 Basic property and class mappings……Page 101
3.3.3 Attribute-oriented programming……Page 107
3.3.4 Manipulating metadata at runtime……Page 109
3.4.1 Identity versus equality……Page 110
3.4.2 Database identity with Hibernate……Page 111
3.4.3 Choosing primary keys……Page 113
3.5 Fine-grained object models……Page 115
3.5.2 Using components……Page 116
3.6.1 Table per concrete class……Page 120
3.6.2 Table per class hierarchy……Page 122
3.6.3 Table per subclass……Page 124
3.6.4 Choosing a strategy……Page 127
3.7 Introducing associations……Page 128
3.7.2 Multiplicity……Page 129
3.7.3 The simplest possible association……Page 130
3.7.4 Making the association bidirectional……Page 131
3.7.5 A parent/child relationship……Page 134
3.8 Summary……Page 135
Working with persistent objects……Page 137
4.1 The persistence lifecycle……Page 138
4.1.1 Transient objects……Page 139
4.1.2 Persistent objects……Page 140
4.1.3 Detached objects……Page 141
4.1.4 The scope of object identity……Page 142
4.1.5 Outside the identity scope……Page 144
4.1.6 Implementing equals() and hashCode()……Page 145
4.2.1 Making an object persistent……Page 149
4.2.2 Updating the persistent state of a detached instance……Page 150
4.2.5 Making a persistent object transient……Page 152
4.2.6 Making a detached object transient……Page 153
4.3.1 Persistence by reachability……Page 154
4.3.2 Cascading persistence with Hibernate……Page 156
4.3.3 Managing auction categories……Page 157
4.3.4 Distinguishing between transient and detached instances……Page 161
4.4 Retrieving objects……Page 162
4.4.1 Retrieving objects by identifier……Page 163
4.4.2 Introducing HQL……Page 164
4.4.3 Query by criteria……Page 165
4.4.5 Fetching strategies……Page 166
4.4.6 Selecting a fetching strategy in mappings……Page 169
4.4.7 Tuning object retrieval……Page 174
4.5 Summary……Page 175
Transactions, concurrency, and caching……Page 177
5.1 Understanding database transactions……Page 179
5.1.1 JDBC and JTA transactions……Page 180
5.1.2 The Hibernate Transaction API……Page 181
5.1.3 Flushing the Session……Page 183
5.1.4 Understanding isolation levels……Page 184
5.1.5 Choosing an isolation level……Page 186
5.1.7 Using pessimistic locking……Page 188
5.2 Working with application transactions……Page 191
5.2.1 Using managed versioning……Page 192
5.2.2 Granularity of a Session……Page 195
5.2.3 Other ways to implement optimistic locking……Page 197
5.3 Caching theory and practice……Page 198
5.3.1 Caching strategies and scopes……Page 199
5.3.2 The Hibernate cache architecture……Page 202
5.3.3 Caching in practice……Page 208
5.4 Summary……Page 217
Advanced mapping concepts……Page 218
6.1 Understanding the Hibernate type system……Page 219
6.1.1 Built-in mapping types……Page 221
6.1.2 Using mapping types……Page 223
6.2.1 Sets, bags, lists, and maps……Page 234
6.3.1 One-to-one associations……Page 243
6.3.2 Many-to-many associations……Page 248
6.4.1 Polymorphic many-to-one associations……Page 257
6.4.2 Polymorphic collections……Page 259
6.4.3 Polymorphic associations and table-per-concrete-class……Page 260
6.5 Summary……Page 262
Retrieving objects efficiently……Page 264
7.1.1 The query interfaces……Page 266
7.1.2 Binding parameters……Page 268
7.1.3 Using named queries……Page 272
7.2.1 The simplest query……Page 273
7.2.3 Polymorphic queries……Page 274
7.2.4 Restriction……Page 275
7.2.5 Comparison operators……Page 276
7.2.6 String matching……Page 278
7.2.7 Logical operators……Page 279
7.2.8 Ordering query results……Page 280
7.3 Joining associations……Page 281
7.3.1 Hibernate join options……Page 282
7.3.2 Fetching associations……Page 283
7.3.3 Using aliases with joins……Page 285
7.3.4 Using implicit joins……Page 288
7.3.5 Theta-style joins……Page 290
7.3.6 Comparing identifiers……Page 291
7.4 Writing report queries……Page 292
7.4.1 Projection……Page 293
7.4.2 Using aggregation……Page 295
7.4.3 Grouping……Page 296
7.4.4 Restricting groups with having……Page 297
7.4.5 Improving performance with report queries……Page 298
7.5.1 Dynamic queries……Page 299
7.5.2 Collection filters……Page 302
7.5.3 Subqueries……Page 304
7.5.4 Native SQL queries……Page 306
7.6.1 Solving the n+1 selects problem……Page 309
7.6.2 Using iterate() queries……Page 312
7.6.3 Caching queries……Page 313
7.7 Summary……Page 315
Writing Hibernate applications……Page 317
8.1 Designing layered applications……Page 318
8.1.1 Using Hibernate in a servlet engine……Page 319
8.1.2 Using Hibernate in an EJB container……Page 334
8.2 Implementing application transactions……Page 343
8.2.1 Approving a new auction……Page 344
8.2.2 Doing it the hard way……Page 345
8.2.3 Using detached persistent objects……Page 347
8.2.4 Using a long session……Page 348
8.2.5 Choosing an approach to application transactions……Page 352
8.3.1 Legacy schemas and composite keys……Page 353
8.3.2 Audit logging……Page 363
8.4 Summary……Page 370
Using the toolset……Page 371
9.1 Development processes……Page 372
9.1.4 Meet in the middle……Page 373
9.2 Automatic schema generation……Page 374
9.2.1 Preparing the mapping metadata……Page 375
9.2.2 Creating the schema……Page 378
9.2.3 Updating the schema……Page 380
9.3.1 Adding meta-attributes……Page 381
9.3.2 Generating finders……Page 383
9.3.3 Configuring hbm2java……Page 385
9.3.4 Running hbm2java……Page 386
9.4.1 Starting Middlegen……Page 387
9.4.2 Restricting tables and relationships……Page 389
9.4.3 Customizing the metadata generation……Page 391
9.4.4 Generating hbm2java and XDoclet metadata……Page 393
9.5.1 Setting value type attributes……Page 395
9.5.2 Mapping entity associations……Page 397
9.5.3 Running XDoclet……Page 398
9.6 Summary……Page 399
SQL fundamentals……Page 401
ORM implementation strategies……Page 405
B.1 Properties or fields?……Page 406
B.2.1 Inheritance from generated code……Page 407
B.2.4 Reflection……Page 408
B.2.5 Runtime bytecode generation……Page 409
B.2.6 “Generic” objects……Page 410
Back in the real world……Page 411
C.1 The strange copy……Page 412
C.3 We don’t need primary keys……Page 413
C.5 Dynamically unsafe……Page 414
C.6 To synchronize or not?……Page 415
C.7 Really fat client……Page 416
C.8 Resuming Hibernate……Page 417
references……Page 418
index……Page 420

Reviews

There are no reviews yet.

Be the first to review “Hibernate in action”
Shopping Cart
Scroll to Top