Hibernate in Action
暫譯: 《Hibernate 實戰》

Christian Bauer, Gavin King

  • 出版商: Manning
  • 出版日期: 2004-08-01
  • 售價: $1,740
  • 貴賓價: 9.5$1,653
  • 語言: 英文
  • 頁數: 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

商品描述(中文翻譯)

描述:

Hibernate 在 Java 界幾乎是如火如荼。這個開源工具為什麼如此受歡迎?因為它自動化了一項繁瑣的任務:將你的 Java 物件持久化到關聯資料庫中。你的物件導向程式碼與關聯資料庫之間不可避免的錯配,要求你編寫將兩者映射的程式碼。這段程式碼通常複雜、繁瑣且開發成本高。Hibernate 為你處理這個映射。

不僅如此,Hibernate 使這一切變得簡單。作為應用程式與資料庫之間的一層,Hibernate 負責物件的加載和保存。Hibernate 應用程式更便宜、更具可攜性,並且對變更更具韌性。而且它們的性能優於你可能自己開發的任何東西。

《Hibernate in Action》仔細解釋了你所需的概念,然後讓你開始實作。它基於一個單一的範例,向你展示如何在實踐中使用 Hibernate,如何處理併發和交易,如何有效地檢索物件並使用快取。

作者創建了 Hibernate,並且每天都會回答 Hibernate 社群的問題——他們知道如何讓 Hibernate 發揮最佳效能。知識和洞察力從這本書的每一個角落滲透出來。

內容概覽:
- ORM 概念
- 開始使用
- 許多實際任務
- Hibernate 應用程式開發流程

目錄:
前言 xi
序言 xiii
致謝 xv
關於本書 xvi
關於 Hibernate3 和 EJB 3 xx
作者在線 xxi
關於書名和封面 xxii

1 理解物件/關聯持久性 1
- 什麼是持久性? 3
- 關聯資料庫 3
- 理解 SQL 4
- 在 Java 中使用 SQL 5
- 物件導向應用程式中的持久性 5
- 範式不匹配 7
- 粒度問題 9
- 子類型問題 10
- 身份問題 11
- 與關聯相關的問題 13
- 物件圖導航問題 14
- 不匹配的成本 15
- 持久性層和替代方案 16
- 分層架構 17
- 使用 SQL/JDBC 手動編碼持久性層 18
- 使用序列化 19
- 考慮 EJB 實體 Bean 20
- 物件導向資料庫系統 21
- 其他選項 22
- 物件/關聯映射 22
- 什麼是 ORM? 23
- 通用 ORM 問題 25
- 為什麼使用 ORM? 26
- 總結 29

2 介紹和整合 Hibernate 30
- 使用 Hibernate 的 "Hello World" 31
- 理解架構 36
- 核心介面 38
- 回調介面 40
- 類型 40
- 擴展介面 41
- 基本配置 41
- 創建 SessionFactory 42
- 在非管理環境中的配置 45
- 在管理環境中的配置 48
- 高級配置設置 51
- 使用基於 XML 的配置 51
- JNDI 綁定的 SessionFactory 53
- 日誌 54
- Java 管理擴展 (JMX) 55
- 總結 58

3 映射持久類 59
- CaveatEmptor 應用程式 60
- 分析業務領域 61
- CaveatEmptor 領域模型 61
- 實現領域模型 64
- 解決關注點泄漏 64
- 透明和自動持久性 65
- 編寫 POJO 67
- 實現 POJO 關聯 69
- 為存取方法添加邏輯 73
- 定義映射元數據 75
- XML 中的元數據 75
- 基本屬性和類別映射 78
- 屬性導向編程 84
- 在運行時操作元數據 86
- 理解物件身份 87
- 身份與相等 87
- 使用 Hibernate 的資料庫身份 88
- 選擇主鍵 90
- 細粒度物件模型 92
- 實體和值類型 93
- 使用組件 93
- 映射類別繼承 97
- 每個具體類別的表 97
- 每個類別層次的表 99
- 每個子類別的表 101
- 選擇策略 104
- 介紹關聯 105
- 管理關聯? 106
- 多重性 106
- 最簡單的關聯 107
- 使關聯雙向 108
- 父/子關係 111
- 總結 112

4 使用持久物件 114
- 持久性生命週期 115
- 短暫物件 116
- 持久物件 117
- 脫離物件 118
- 物件身份的範圍 119
- 在身份範圍外 121
- 實現 equals() 和 hashCode() 122
- 持久性管理器 126
- 使物件持久 126
- 更新脫離實例的持久狀態 127
- 檢索持久物件 129
- 更新持久物件 129
- 使持久物件短暫 129
- 使脫離物件短暫 130
- 在 Hibernate 中使用傳遞持久性 131
- 透過可達性持久性 131
- 使用 Hibernate 的級聯持久性 133
- 管理拍賣類別 134
- 區分短暫和脫離實例 138
- 檢索物件 139
- 通過識別符檢索物件 140
- 介紹 HQL 141
- 根據條件查詢 142
- 根據範例查詢 143
- 獲取策略 143
- 在映射中選擇獲取策略 146
- 調整物件檢索 151
- 總結 152

5 交易、併發和快取 154
- 交易、併發和快取 154
- 理解資料庫交易 156
- JDBC 和 JTA 交易 157
- Hibernate 交易 API 158
- 刷新 Session 160
- 理解隔離級別 161
- 選擇隔離級別 163
- 設定隔離級別 165
- 使用悲觀鎖定 165
- 使用應用程式交易 168
- 使用管理版本控制 169
- Session 的粒度 172
- 實現樂觀鎖定的其他方法 174
- 快取理論與實踐 175
- 快取策略和範圍 176
- Hibernate 快取架構 179
- 實踐中的快取 185
- 總結 194

6 高級映射概念 195
- 理解 Hibernate 類型系統 196
- 內建映射類型 198
- 使用映射類型 200
- 映射值類型的集合 211
- 集合、袋、列表和映射 211
- 映射實體關聯 220
- 一對一關聯 220
- 多對多關聯 225
- 映射多態關聯 234
- 多態多對一關聯 234
- 多態集合 236
- 多態關聯和每個具體類別的表 237
- 總結 239

7 高效檢索物件 241
- 執行查詢 243
- 查詢介面 243
- 綁定參數 245
- 使用命名查詢 249
- 物件的基本查詢 250
- 最簡單的查詢 250
- 使用別名 251
- 多態查詢 251
- 限制 252
- 比較運算符 253
- 字串匹配 255
- 邏輯運算符 256
- 排序查詢結果 257
- 連接關聯 258
- Hibernate 連接選項 259
- 獲取關聯 260
- 在連接中使用別名 262
- 使用隱式連接 265
- Theta 風格的連接 267
- 比較識別符 268
- 編寫報告查詢 269
- 投影 270
- 使用聚合 272
- 分組 273
- 使用 having 限制分組 274
- 通過報告查詢提高性能 275
- 高級查詢技術 276
- 動態查詢 276
- 集合過濾器 279
- 子查詢 281
- 原生 SQL 查詢 283
- 優化物件檢索 286
- 解決 n+1 選擇問題 286
- 使用 iterate() 查詢 289
- 快取查詢 290
- 總結 292

8 編寫 Hibernate 應用程式 294
- 設計分層應用程式 295
- 在 servlet 引擎中使用 Hibernate 296
- 在 EJB 容器中使用 Hibernate 311
- 實現應用程式交易 320
- 批准新拍賣 321
- 硬路徑實現 322
- 使用脫離持久物件 324
- 使用長期 Session 325
- 選擇應用程式交易的方法 329
- 處理特殊類型的資料 330
- 遺留架構和複合鍵 330
- 審計日誌 340
- 總結 347

9 使用工具集 348
- 開發流程 349
- 自上而下 350
- 自下而上 350
- 中間向外(元數據導向) 350
- 中間會合 350
- 來回傳遞 351
- 自動架構生成 351
- 準備映射元數據 352
- 創建架構 355
- 更新架構 357
- 生成 POJO 代碼 358
- 添加元屬性 358
- 生成查找器 360
- 配置 hbm2java 362
- 執行 hbm2java 363
- 現有架構和 Middlegen 364
- 啟動 Middlegen 364
- 限制表和關係 366
- 自定義元數據生成 368
- 生成 hbm2java 和 XDoclet 元數據 370
- XDoclet 372
- 設定值類型屬性 372
- 映射實體關聯 374
- 執行 XDoclet 375
- 總結 376

附錄 A:SQL 基礎 378
附錄 B:ORM 實現策略 382
- 屬性或欄位? 383