Cover image for Professional Hibernate
Title:
Professional Hibernate
Personal Author:
Publication Information:
Indianapolis, IN : Wiley Publishing, 2004
ISBN:
9780764576775
Added Author:

Available:*

Library
Item Barcode
Call Number
Material Type
Item Category 1
Status
Searching...
30000010075938 QA76.76.M54 P83 2004 Open Access Book Book
Searching...

On Order

Summary

Summary

What is this book about?

This book is written for professional Java developers who already understand how to build server-side Java applications.  The book assumes no previous experience with Hibernate, though readers should have a general familiarity with databases and Web development.

What does this book cover?

After a quick overview of Hibernate in the first two chapters, the authors jump right to the code.  They show how to do the following:

Obtain and install Hibernate Build the Hibernate development environment Use Hibernate to connect to databases Use Hibernate to create persistent classes and objects Use the Hibernate database query language and transaction management functions Use the Hibernate APIs

After covering these essentials, the authors go further, showing readers how to use Hibernate in the real world.  This means demonstrating how to use Hibernate with other popular tools that readers are using (including Eclipse, Tomcat, Maven, Struts, and XDoclet). This book takes a very real-world, hands-on approach to these topics and includes many working code examples, as well as a sophisticated sample application.


Author Notes

Eric Pugh is a member of the Maven development team and an experienced Java enterprise developer specializing in database application design and development, and open source tool integration. He has contributed Hibernate-related code to many projects, including XDoclet and OSWorkflow, and is currently leading development of the Hibernate plugin for Maven. Eric has built several Hibernate applications for clients (including a Web-based lab automation application) and regularly uses Hibernate with Eclipse and Maven. In addition to writing documentation and specifications, Eric has written for OnJava.

Joseph D. Gradecki is a software engineer at Comprehensive Software Solutions, where he works on their SABIL product, an enterprise-level securities processing system. He has built numerous dynamic, enterprise application using Java, Hibernate, MySQL, XML, AspectJ, servlets, JSPs, Resin, BroadVision, and other technologies. He is the author of Mastering JXTA and the co-author of MySQL and Java Developers Guide and Professional Java Tools for Extreme Programming . Joe holds Bachelors and Masters degrees in Computer Science and is currently pursuing a Ph.D.


Table of Contents

Introductionp. ix
Chapter 1 Introduction to Mapping Objects to Relational Databasesp. 1
Serializationp. 2
XMLp. 2
Object-Oriented Database Systemsp. 3
Mappingp. 3
Primary Keys, Timestamps, and Version Numbersp. 8
Handling Inheritancep. 8
Working With Relationshipsp. 11
Summaryp. 14
Chapter 2 Introduction to Hibernatep. 15
Hibernatep. 15
Hibernate Architecturep. 16
Hibernate Configurationp. 18
Hibernate Sessionsp. 20
Hibernate Callbacksp. 21
Hibernate's Support for Other Technologiesp. 22
Summaryp. 22
Chapter 3 Hibernate Development Environmentp. 23
Obtaining Hibernatep. 23
Hibernate Prerequisites and Requirementsp. 24
Installing Hibernatep. 25
Hibernate Configuration Filep. 26
Hooking Up a Database Serverp. 26
Setting Up Hibernate to Use MySQLp. 27
Setting Up Hibernate to Use Microsoft SQL Serverp. 27
A Standalone Hibernate Applicationp. 28
Creating the Java Classp. 28
Creating a Database Tablep. 30
Building a Mapping Document for Database Tablesp. 30
Application Skeleton Codep. 33
Loading the Mapping into an Applicationp. 38
A Servlet-Based Hibernate Applicationp. 46
Installing and Configuring Tomcatp. 46
Setting Up Tomcat Database Accessp. 47
Adding Hibernate to the Web Applicationp. 49
Interface Pagep. 50
Writing a Servlet to Use Hibernatep. 51
Summaryp. 53
Chapter 4 Database Connecting and Schema Generationp. 55
Overview of Hibernate JDBC Propertiesp. 56
hibernate.connection.driverclassp. 56
hibernate.connection.urlp. 58
hibernate.connection.usernamep. 58
hibernate.connection.passwordp. 58
hibernate.connection.pool_sizep. 58
hibernate.connection.datasourcep. 58
hibernate.jndi.urlp. 59
hibernate.jndi.classp. 59
hibernate.dialectp. 59
hibernate.default_schemap. 59
hibernate.Session_-factory_namep. 59
hibernate.use_outer_joinp. 59
hibernate.max_fetch_depthp. 59
hibernate.jdbc.fetch_sizep. 60
hibernate.jdbc.batch_sizep. 60
hibernate.jdbc.use_scrollable_resultsetp. 60
hibernate.jdbc.use_streams_for_binaryp. 60
hibernate.cglib.use_reflection_optimizerp. 60
hibernate.jndi.[left angle bracket]property[right angle bracket]p. 60
hibernate.connection.isolationp. 60
hibernate.connection.provider_classp. 61
hibernate.transaction.factory_classp. 61
jta.UserTransactionp. 61
hibernate.show_sqlp. 61
Query Substitutionsp. 62
SQL Dialect Determinationp. 62
Using Connection Poolingp. 64
Using Hibernate's Built-in Poolingp. 65
Using C3P0p. 65
Using Apache DBCPp. 66
Using Proxoolp. 66
JDBC Database Connectionp. 67
Using More Than One Database Serverp. 68
Building the Mapping Documentp. 69
[left angle bracket]hibernate-mapping[right angle bracket] Elementp. 69
[left angle bracket]class[right angle bracket] Elementp. 70
[left angle bracket]id[right angle bracket] Elementp. 72
[left angle bracket]generator[right angle bracket] Elementp. 73
[left angle bracket]composite-id[right angle bracket] Elementp. 75
[left angle bracket]discriminator[right angle bracket] Elementp. 76
[left angle bracket]version[right angle bracket] Elementp. 77
[left angle bracket]timestamp[right angle bracket] Elementp. 78
[left angle bracket]property[right angle bracket] Elementp. 78
Relationship Elementsp. 80
[left angle bracket]many-to-one[right angle bracket] Elementp. 80
[left angle bracket]one-to-one[right angle bracket] Elementp. 81
[left angle bracket]component[right angle bracket] Elementp. 82
[left angle bracket]subclass[right angle bracket] Elementp. 82
[left angle bracket]joined-subclass[right angle bracket] Elementp. 83
Collection Elementsp. 84
[left angle bracket]key[right angle bracket] Elementp. 85
[left angle bracket]index[right angle bracket] Elementp. 86
[left angle bracket]element[right angle bracket] Elementp. 86
Summaryp. 86
Chapter 5 Creating Persistent Classesp. 87
Creating Persistent Java Classesp. 87
Mapping a Basic Java Classp. 88
Mapping a Class with Binary Datap. 93
Mapping a Serializable Classp. 95
Mapping a Class with Data/Calendar Attributesp. 97
Mapping a Read-Only Classp. 99
Mapping Classes Using Versioning/Timestampsp. 102
Mapping Inheritance with Java Classesp. 107
Persisting Interfacesp. 117
Mapping Enumsp. 119
Working with Column Formulasp. 122
Using the Session Patternp. 124
Summaryp. 126
Chapter 6 Working with Collectionsp. 127
Associationsp. 127
Index Elementsp. 128
Element Elementsp. 129
Bidirectional Associationsp. 130
Lazy Initializationp. 131
Mapping Maps/SortedMapsp. 131
Mapping a Values Mapp. 131
Mapping an Object Map: [left angle bracket]many-to-many[right angle bracket] Elementp. 135
Mapping a TreeMapp. 140
Mapping Set/SortedSetsp. 147
SortedSet Interface Mappingp. 151
Mapping Listsp. 152
Bag Mappingp. 156
Mapping Arraysp. 157
Mapping a Bidirectional Associationp. 158
Summaryp. 160
Chapter 7 Using Persistent Objectsp. 161
Persisting Objectsp. 161
Loading Data into an Objectp. 164
Using Previous Sessionsp. 165
Flushing Objectsp. 166
Deleting Objectsp. 166
Refreshing Objectsp. 168
Updating Objectsp. 168
Finding Objectsp. 169
Finding Large Resultsetsp. 171
Filtering Collectionsp. 171
Scalar Queriesp. 172
Queries and Named Queriesp. 173
Query Results Controlp. 176
Single Rowp. 178
Named Queriesp. 178
Named Parametersp. 179
Query Timeoutp. 180
SQL Queriesp. 180
Criteria Objectsp. 181
Summaryp. 184
Chapter 8 Hibernate Query Languagep. 185
Chapter Examplep. 185
Example Classesp. 185
Example Mapping Documentp. 189
Example Tablesp. 191
Example Applicationp. 191
Example Rowsp. 192
Example Usep. 193
Select Clausep. 194
Narrowing the SELECT Using the WHERE Clausep. 196
Working with Collections in HQLp. 197
.size, size()p. 197
.minIndex, minindex(), .maxIndex, maxindex()p. 197
index()p. 198
any(), some(), all(), exists(), in(), elements(), indices()p. 198
[]p. 199
Other HQL WHERE Expressionsp. 199
Logicalsp. 199
NULL Expressionp. 199
Groupingsp. 200
Scalar Functionsp. 200
Equalityp. 201
Named Parametersp. 201
Booleansp. 201
Subselectsp. 202
Polymorphismp. 202
Order By Clausep. 203
Aggregate Functionsp. 204
Group By Clausep. 204
HAVING Clausep. 205
Working with HQL Joinsp. 205
Left Outer Joinp. 205
Right Outer Joinp. 206
Inner Joinp. 206
Full Joinp. 206
Fetch Joinp. 206
Summaryp. 206
Chapter 9 Hibernate Cachingp. 207
Why Cache? What Does Hibernate Provide?p. 207
Caching the Survey Object Example Codep. 208
Setting Up a SessionFactory Cachep. 212
Using the Persistent Object Cachep. 213
Read-Only Cache Usagep. 213
Read-Write Cache Usagep. 214
Nonstrict Read-Write Cache Usagep. 214
Transactional Cache Usagep. 214
SessionFactory Support Methodsp. 214
Using the Query Cachep. 215
Session Cache Functionalityp. 216
Setting Up EHCachep. 216
When Not to Use Cachingp. 218
Summaryp. 219
Chapter 10 Hibernate Transactions and Lockingp. 221
What Are Transactions?p. 223
Configurationp. 223
Database Supportp. 224
Using Transactionsp. 225
The Transaction APIp. 226
Transaction Example Using MySQLp. 227
ISAM Table Typep. 228
InnoDB Table Typep. 228
Forced Rollback Examplep. 229
Optimal Session Usep. 229
Lockingp. 230
Summaryp. 234
Chapter 11 J2EE and Hibernatep. 235
Installing an Application Serverp. 235
Configuring Tomcat for Hibernate with JNDIp. 235
Configuring Tomcat for JNDIp. 236
Creating the Necessary Hibernate Configuration Filep. 236
SessionFactory Singleton Classp. 237
Building a Stateless Session Beanp. 238
Building a Stateful Session Beanp. 240
Using Container Managed Transactions (CMT)p. 242
Summaryp. 245
Chapter 12 Hibernate and DAO Design Patternp. 247
Data Access Object Design Patternp. 247
Factory Method Implementationp. 250
Abstract Factory Implementationp. 252
Concrete DAO Examplep. 253
Building a DAO Factoryp. 254
Building Specific Data Source Factoriesp. 254
Building the DAO Objectsp. 255
Testing It Allp. 259
Summaryp. 260
Chapter 13 Hibernate and XDocletp. 261
Introduction to XDocletp. 262
What Is Javadoc?p. 263
How XDoclet Worksp. 264
Code Generation Templatingp. 265
Why XDoclet Simplifies Developmentp. 265
Installing XDocletp. 266
Using XDoclet with Hibernatep. 266
Simple Examplep. 266
Generating Hibernate.cfg.xmlp. 268
Generating an MBean Descriptor File for JBossp. 270
Tagging Source Files with Mapping Attributesp. 272
Hibernate XDoclet Tags and Descriptionp. 282
@hibernate.classp. 282
@hibernate.cachep. 283
@hibernate.discriminatorp. 283
@hibernate.joined-subclassp. 283
@hibernate.joined-subclass-keyp. 284
@hibernate.queryp. 284
@hibernate.subclassp. 284
@hibernate.arrayp. 284
@hibernate.bag (0..1)p. 285
@hibernate.collection-cachep. 285
@hibernate.collection-composite-elementp. 286
@hibernate.collection-elementp. 286
@hibernate.collection-indexp. 286
@hibernate.collection-keyp. 287
@hibernate.collection-key-column (0..*)p. 287
@hibernate.collection-many-to-manyp. 287
@hibernate.collection-one-to-manyp. 287
@hibernate.columnp. 288
@hibernate.componentp. 288
@hibernate.generator-paramp. 288
@hibernate.idp. 289
@hibernate.index-many-to-manyp. 289
@hibernate.listp. 290
@hibernate.many-to-onep. 290
@hibernate.mapp. 291
@hibernate.one-to-onep. 291
@hibernate.primitive-arrayp. 292
@hibernate.propertyp. 292
@hibernate.setp. 292
@hibernate.timestampp. 293
@hibernate.versionp. 293
Full-Circle Processp. 294
Tips on Using XDocletp. 304
Summaryp. 305
Chapter 14 Hibernate and Mavenp. 307
Installing Mavenp. 308
Using Mavenp. 308
The Project Object Modelp. 309
Five-Minute Tutorial to Using Mavenp. 310
Generating Hibernate Files with Mavenp. 312
Scripting Directly in Maven.xmlp. 314
Using the Hibernate Plug-in for Mavenp. 317
Putting It All Togetherp. 319
Generating Filesp. 319
Configuring a Database Prior to Running Unit Testsp. 320
Advantages over Antp. 327
Things to Be Aware Ofp. 327
Summaryp. 328
Chapter 15 Hibernate Extensionsp. 329
Toolsp. 329
SchemaExport/SchemaUpdatep. 329
Hibernate Extensionsp. 342
AndroMDAp. 355
MiddleGenp. 358
Summaryp. 361
Chapter 16 Hibernate and Eclipsep. 363
Hibernatorp. 363
Database Connectionp. 364
Creating a Mapping Documentp. 366
Querying the Databasep. 367
Creating a Schemap. 367
Updating the Schemap. 367
HiberClipsep. 368
Configuring a JDBC Connectionp. 369
Creating a Mapping Documentp. 369
Creating Java Code from a Mapping Documentp. 370
Creating a Schema Export or Updating a Schemap. 370
Hibernate Synchronizerp. 370
Configuration File Wizardp. 370
Mapping Document Wizardp. 371
Summaryp. 372
Chapter 17 Using Velocity, Struts, and Hibernatep. 373
Brief Introduction to Strutsp. 373
Struts Flow Diagramp. 373
Installing Strutsp. 374
A Sample Applicationp. 374
Building the ActionFormp. 375
RegisterForm Codep. 376
Creating an Actionp. 377
RegisterAction Codep. 377
Configuring Strutsp. 378
Struts Configuration Filep. 382
Toolbox.xml Filep. 385
Success Pagep. 385
Success.vm Templatep. 385
Success under Struts and Velocityp. 385
Register Pagep. 385
Register.VM Templatep. 387
Compilep. 387
Runp. 387
Summaryp. 388
Chapter 18 Hibernate and AspectJp. 389
What Is Aspect-Oriented Programmingp. 389
Where OOP Has Brought Usp. 390
What OOADP Did for Computer Sciencep. 390
Problems Resulting from OOPp. 392
Results of Tangled Codep. 396
How AOP Solves OOP Problemsp. 396
Introduction to AspectJp. 398
AOP Language Specificationp. 399
AOP Language Implementationp. 401
AspectJp. 402
Example Aspectp. 403
Using AspectJ with Hibernatep. 404
Summaryp. 405
Chapter 19 Hibernate Interceptorsp. 407
Interceptor Interfacep. 407
Building an Interceptorp. 408
Summaryp. 412
Appendix A Hibernate Database Connectivityp. 413
DB2p. 413
DB2/400p. 414
HypersonicSQLp. 414
Interbasep. 414
McKoi SQLp. 415
Microsoft SQL Serverp. 415
MySQLp. 416
Oraclep. 416
Pointbasep. 416
PostgreSQLp. 417
SAP DBp. 417
Sybasep. 417
Appendix B Getting Involved with Hibernatep. 419
Hibernate Forumsp. 419
Hibernate Wikip. 420
Contributing to the Further Development of Hibernatep. 420
Checking Out the Source and Building Itp. 420
Development Mailing Listp. 421
Issue Trackingp. 421
More Information on Open Sourcep. 422
Indexp. 423