Hibernate in Action

Christian Bauer, Gavin King

  • 出版商: Manning
  • 出版日期: 2004-08-01
  • 售價: $1,790
  • 貴賓價: 9.5$1,701
  • 語言: 英文
  • 頁數: 408
  • 裝訂: Paperback
  • ISBN: 193239415X
  • ISBN-13: 9781932394153
  • 相關分類: Java 相關技術
  • 已過版

買這商品的人也買了...

相關主題

商品描述

Description:

Hibernate 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.

What's Inside

  • ORM concepts
  • Getting started
  • Many real-world tasks
  • The Hibernate application development processes

 

Table of Contents:

foreword xi
preface xiii
acknowledgments xv
about this book xvi
about Hibernate3 and EJB 3 xx
author online xxi
about the title and cover xxii

1 Understanding object/relational persistence 1
What is persistence? 3
Relational databases 3 - Understanding SQL 4 - Using SQL in Java 5 - Persistence in object-oriented applications 5
The paradigm mismatch 7
The problem of granularity 9 - The problem of subtypes 10 - The problem of identity 11 - Problems relating to associations 13 - The problem of object graph navigation 14 - The cost of the mismatch 15
Persistence layers and alternatives 16
Layered architecture 17 - Hand-coding a persistence layer with SQL/JDBC 18 - Using serialization 19 - Considering EJB entity beans 20 - Object-oriented database systems 21 - Other options 22
Object/relational mapping 22
What is ORM? 23 - Generic ORM problems 25 - Why ORM? 26
Summary 29
2 Introducing and integrating Hibernate 30
"Hello World" with Hibernate 31
Understanding the architecture 36
The core interfaces 38 - Callback interfaces 40 - Types 40 - Extension interfaces 41
Basic configuration 41
Creating a SessionFactory 42 - Configuration in non-managed environments 45 - Configuration in managed environments 48
Advanced configuration settings 51
Using XML-based configuration 51 - JNDI-bound SessionFactory 53 - Logging 54 - Java Management Extensions (JMX) 55
Summary 58
3 Mapping persistent classes 59
The CaveatEmptor application 60
Analyzing the business domain 61 - The CaveatEmptor domain model 61
Implementing the domain model 64
Addressing leakage of concerns 64 - Transparent and automated persistence 65 - Writing POJOs 67 - Implementing POJO associations 69 - Adding logic to accessor methods 73
Defining the mapping metadata 75
Metadata in XML 75 - Basic property and class mappings 78 - Attribute-oriented programming 84 - Manipulating metadata at runtime 86
Understanding object identity 87
Identity versus equality 87 - Database identity with Hibernate 88 - Choosing primary keys 90
Fine-grained object models 92
Entity and value types 93 - Using components 93
Mapping class inheritance 97
Table per concrete class 97 - Table per class hierarchy 99 - Table per subclass 101 - Choosing a strategy 104
Introducing associations 105
Managed associations? 106 - Multiplicity 106 - The simplest possible association 107 - Making the association bidirectional 108 - A parent/child relationship 111
Summary 112
4 Working with persistent objects 114
The persistence lifecycle 115
Transient objects 116 - Persistent objects 117 - Detached objects 118 - The scope of object identity 119 - Outside the identity scope 121 - Implementing equals() and hashCode() 122
The persistence manager 126
Making an object persistent 126 - Updating the persistent state of a detached instance 127 - Retrieving a persistent object 129 - Updating a persistent object 129 - Making a persistent object transient 129 - Making a detached object transient 130
Using transitive persistence in Hibernate 131
Persistence by reachability 131 - Cascading persistence with Hibernate 133 - Managing auction categories 134 - Distinguishing between transient and detached instances 138
Retrieving objects 139
Retrieving objects by identifier 140 - Introducing HQL 141 - Query by criteria 142 - Query by example 143 - Fetching strategies 143 - Selecting a fetching strategy in mappings 146 - Tuning object retrieval 151
Summary 152
5 Transactions, concurrency, and caching 154
Transactions, concurrency, and caching 154
Understanding database transactions 156
JDBC and JTA transactions 157 - The Hibernate Transaction API 158 - Flushing the Session 160 - Understanding isolation levels 161 - Choosing an isolation level 163 - Setting an isolation level 165 - Using pessimistic locking 165
Working with application transactions 168
Using managed versioning 169 - Granularity of a Session 172 - Other ways to implement optimistic locking 174
Caching theory and practice 175
Caching strategies and scopes 176 - The Hibernate cache architecture 179 - Caching in practice 185
Summary 194
6 Advanced mapping concepts 195
Understanding the Hibernate type system 196
Built-in mapping types 198 - Using mapping types 200
Mapping collections of value types 211
Sets, bags, lists, and maps 211
Mapping entity associations 220
One-to-one associations 220 - Many-to-many associations 225
Mapping polymorphic associations 234
Polymorphic many-to-one associations 234 - Polymorphic collections 236 - Polymorphic associations and table-per- concrete-class 237
Summary 239
7 Retrieving objects efficiently 241
Executing queries 243
The query interfaces 243 - Binding parameters 245 - Using named queries 249
Basic queries for objects 250
The simplest query 250 - Using aliases 251 - Polymorphic queries 251 - Restriction 252 - Comparison operators 253 - String matching 255 - Logical operators 256 - Ordering query results 257
Joining associations 258
Hibernate join options 259 - Fetching associations 260 - Using aliases with joins 262 - Using implicit joins 265 - Theta-style joins 267 - Comparing identifiers 268
Writing report queries 269 Projection 270 - Using aggregation 272 - Grouping 273
Restricting groups with having 274 - Improving performance with report queries 275
Advanced query techniques 276
Dynamic queries 276 - Collection filters 279 - Subqueries 281 - Native SQL queries 283
Optimizing object retrieval 286
Solving the n+1 selects problem 286 - Using iterate() queries 289 - Caching queries 290
Summary 292
8 Writing Hibernate applications 294
Designing layered applications 295
Using Hibernate in a servlet engine 296 - Using Hibernate in an EJB container 311
Implementing application transactions 320
Approving a new auction 321 - Doing it the hard way 322 - Using detached persistent objects 324 - Using a long session 325 - Choosing an approach to application transactions 329
Handling special kinds of data 330
Legacy schemas and composite keys 330 - Audit logging 340
Summary 347
9 Using the toolset 348
Development processes 349
Top down 350 - Bottom up 350 - Middle out (metadata oriented) 350 - Meet in the middle 350 - Roundtripping 351
Automatic schema generation 351
Preparing the mapping metadata 352 - Creating the schema 355 - Updating the schema 357
Generating POJO code 358
Adding meta-attributes 358 - Generating finders 360 - Configuring hbm2java 362 - Running hbm2java 363
Existing schemas and Middlegen 364
Starting Middlegen 364 - Restricting tables and relationships 366 - Customizing the metadata generation 368 - Generating hbm2java and XDoclet metadata 370
XDoclet 372
Setting value type attributes 372 - Mapping entity associations 374 - Running XDoclet 375
Summary 376
appendix A: SQL fundamentals 378
appendix B: ORM implementation strategies 382
Properties or fields? 383
Dirty-checking strategies 384
appendix C: Back in the real world 388
The strange copy 389
The more the better 390
We don?t need primary keys 390
Time isn?t linear 391
Dynamically unsafe 391
To synchronize or not? 392
Really fat client 393
Resuming Hibernate 394
 
references 395
index 397