Beginning Hibernate - Jeff Linwood, Dave Minter

Beginning Hibernate (eBook)

eBook Download: PDF
2010 | 2nd ed.
400 Seiten
Apress (Verlag)
978-1-4302-2851-6 (ISBN)
Systemvoraussetzungen
39,99 inkl. MwSt
  • Download sofort lieferbar
  • Zahlungsarten anzeigen

Beginning Hibernate, Second Edition is ideal if you're experienced in Java with databases (the traditional, or 'connected,' approach), but new to open-source, lightweight Hibernate-the de facto object-relational mapping and database-oriented application development framework.

This book packs in information about the release of the Hibernate 3.5 persistence layer and provides a clear introduction to the current standard for object-relational persistence in Java. And since the book keeps its focus on Hibernate without wasting time on nonessential third-party tools, you'll be able to immediately start building transaction-based engines and applications.

Experienced authors Dave Minter and Jeff Linwood provide more in-depth examples than any other book for Hibernate beginners. The authors also present material in a lively, example-based manner-not a dry, theoretical, hard-to-read fashion.



Jeff Linwood has been involved in software programming since he had a 286 in high school. He got caught up with the Internet when he got access to a UNIX shell account, and it has been downhill ever since. Jeff has published articles on several Jakarta Apache open source projects in Dr. Dobb's Journal, CNET's Builder.com, and JavaWorld. Jeff has a bachelor's degree in chemical engineering from Carnegie Mellon University. He currently works for the Gossamer Group in Austin, Texas, on content management and web application syndication systems. He gets to play with all the latest open source projects there. Jeff also co-authored Professional Struts Applications, Building Portals with the Java Portlet API, and Pro Hibernate 3. He was a technical reviewer for Enterprise Java Development on a Budget and Extreme Programming with Ant.
Beginning Hibernate, Second Edition is ideal if you're experienced in Java with databases (the traditional, or "e;connected,"e; approach), but new to open-source, lightweight Hibernate-the de facto object-relational mapping and database-oriented application development framework. This book packs in information about the release of the Hibernate 3.5 persistence layer and provides a clear introduction to the current standard for object-relational persistence in Java. And since the book keeps its focus on Hibernate without wasting time on nonessential third-party tools, you ll be able to immediately start building transaction-based engines and applications. Experienced authors Dave Minter and Jeff Linwood provide more in-depth examples than any other book for Hibernate beginners. The authors also present material in a lively, example-based manner not a dry, theoretical, hard-to-read fashion.

Jeff Linwood has been involved in software programming since he had a 286 in high school. He got caught up with the Internet when he got access to a UNIX shell account, and it has been downhill ever since. Jeff has published articles on several Jakarta Apache open source projects in Dr. Dobb's Journal, CNET's Builder.com, and JavaWorld. Jeff has a bachelor's degree in chemical engineering from Carnegie Mellon University. He currently works for the Gossamer Group in Austin, Texas, on content management and web application syndication systems. He gets to play with all the latest open source projects there. Jeff also co-authored Professional Struts Applications, Building Portals with the Java Portlet API, and Pro Hibernate 3. He was a technical reviewer for Enterprise Java Development on a Budget and Extreme Programming with Ant.

Contents at a Glance 4
Table of Contents 6
About the Authors 16
About the Technical Reviewer 17
Acknowledgments 18
Introduction 19
Who This Book Is For 19
How This Book Is Structured 19
Downloading the Code 21
Contacting the Authors 21
CHAPTER 1 An Introduction to Hibernate 3.5 22
Plain Old Java Objects (POJOs) 22
Origins of Hibernate and Object-Relational Mapping 24
Hibernate As a Persistence Solution 25
A Hibernate Hello World Example 26
Mappings 27
Summary 28
CHAPTER 2 Integrating and Configuring Hibernate 29
The Steps Needed to Integrate and Configure Hibernate 29
Understanding Where Hibernate Fits in Your Java Application 30
Deploying Hibernate 31
Required Libraries for Running Hibernate 3.5 31
JMX and Hibernate 32
Hibernate Configuration 32
Hibernate Properties 34
XML Configuration 38
Annotated Classes 39
Naming Strategy 40
Using a Container-Managed Data Source 41
The Session Factory 41
SQL Dialects 42
Summary 45
CHAPTER 3 Building a Simple Application 46
Installing the Tools 46
Hibernate and Hibernate Tools 46
Simple Logging Facade for Java (SLF4J) 1.5.11 47
HSQLDB 2.0.0 47
Ant 1.8.0 48
The Ant Tasks 51
Creating a Hibernate Configuration File 52
Running the Message Example 54
Persisting Multiple Objects 57
Creating Persistence Classes 58
Creating the Object Mappings 61
Creating the Tables 67
Sessions 69
The Session and Related Objects 69
Using the Session 71
The Example Client 73
Summary 78
CHAPTER 4 The Persistence Life Cycle 79
Introduction to the Life Cycle 79
Entities, Classes, and Names 80
Identifiers 81
Entities and Associations 81
Saving Entities 85
Object Equality and Identity 86
Loading Entities 87
Refreshing Entities 88
Updating Entities 89
Deleting Entities 90
Cascading Operations 90
Lazy Loading, Proxies, and Collection Wrappers 92
Querying Objects 93
Summary 93
CHAPTER 5 An Overview of Mapping 94
Why Mapping Cannot Be Automated 95
Primary Keys 97
Lazy Loading 99
Associations 99
The One-to-One Association 101
The One-to-Many and Many-to-One Association 103
The Many-to-Many Association 105
Applying Mappings to Associations 106
Other Information Represented in Mappings 106
Specification of (Database) Column Types and Sizes 106
The Mapping of Inheritance Relationships to the Database 106
Primary Key 107
The Use of SQL Formula–Based Properties 107
Mandatory and Unique Constraints 107
Cascading of Operations 107
Summary 107
CHAPTER 6 Mapping with Annotations 108
Creating Hibernate Mappings with Annotations 108
Cons of Annotations 108
Pros of Annotations 108
Choosing Which to Use 110
Using Annotations in Your Application 110
JPA 2 Persistence Annotations 110
Entity Beans with @Entity 112
Primary Keys with @Id and @GeneratedValue 112
Generating Primary Key Values with @SequenceGenerator 114
Generating Primary Key Values with @TableGenerator 115
Compound Primary Keys with @Id, @IdClass, or @EmbeddedId 116
Database Table Mapping with @Table and @SecondaryTable 120
Persisting Basic Types with @Basic 122
Omitting Persistence with @Transient 122
Mapping Properties and Fields with @Column 123
Modeling Entity Relationships 124
Mapping an Embedded (Component) One-to-One Association 124
Mapping a Conventional One-to-One Association 125
Mapping a Many-to-One or One-to-Many Association 126
Mapping a Many-to-Many Association 130
Inheritance 131
Single Table 132
Joined 133
Table per Class 133
Choosing Between Inheritance Types When Modeling Inheritance 134
Other JPA 2 Persistence Annotations 134
Temporal Data 134
Element Collections 135
Large Objects 135
Mapped Superclasses 136
Ordering Collections with @OrderColumn 136
Named Queries (HQL or JPQL) 137
Named Native Queries (SQL) 138
Configuring the Annotated Classes 138
Hibernate 3–Specific Persistence Annotations 139
@Entity 140
Sorting Collections with @Sort 140
Applying Indexes with @Table and @Index 141
Restricting Collections with @Where 141
Alternative Key Generation Strategies with @GenericGenerator 141
Using Ant with Annotation-Based Mappings 142
Code Listings 143
Summary 148
CHAPTER 7 Creating Mappings with Hibernate XML Files 149
Hibernate Types 149
Entities 149
Components 150
Values 150
The Anatomy of a Mapping File 152
The < hibernate-mapping>
The < class>
The < id>
The < property>
The < component>
The < one-to-one>
The < many-to-one>
The Collection Elements 168
The set Collection 170
The list Collection 172
The idbag Collection 173
The map Collection 174
The bag Collection 175
Mapping Simple Classes 176
Mapping Composition 178
Mapping Other Associations 181
Mapping Collections 184
Mapping Inheritance Relationships 187
One Table per Concrete Class 187
One Table per Subclass 188
One Table per Class Hierarchy 190
More Exotic Mappings 191
The any Tag 191
The array Tag 192
The < dynamic-component>
Summary 192
CHAPTER 8 Using the Session 193
Sessions 193
Transactions and Locking 197
Transactions 197
Locking 200
Deadlocks 201
Caching 205
Threads 207
Summary 208
CHAPTER 9 Searches and Queries 209
Hibernate Query Language (HQL) 209
Syntax Basics 210
UPDATE 210
DELETE 210
INSERT 211
SELECT 211
The First Example with HQL 212
Logging and Commenting the Underlying SQL 216
Logging the SQL 216
Commenting the Generated SQL 217
The from Clause and Aliases 218
The select Clause and Projection 218
Using Restrictions with HQL 219
Using Named Parameters 220
Paging Through the Result Set 221
Obtaining a Unique Result 221
Sorting Results with the order by Clause 222
Associations 222
Aggregate Methods 223
Bulk Updates and Deletes with HQL 224
Named Queries for HQL and SQL 225
Using Native SQL 227
Summary 229
CHAPTER 10 Advanced Queries Using Criteria 230
Using the Criteria API 230
Using Restrictions with Criteria 230
Paging Through the Result Set 234
Obtaining a Unique Result 234
Sorting the Query’s Results 235
Associations 235
Distinct Results 236
Projections and Aggregates 236
Query By Example (QBE) 238
Summary 240
CHAPTER 11 Filtering the Results of Searches 241
When to Use Filters 241
Defining and Attaching Filters 242
Filters with Annotations 242
Filters with XML Mapping Documents 243
Using Filters in Your Application 243
A Basic Filtering Example 244
Summary 248
CHAPTER 12 Case Study – Using Hibernate with an Existing Database 249
Setting up the Database 249
Downloading the Data 249
Understanding the Data 250
Geographic Names 250
Country Subdivision Codes 252
Second-Level Subdivisions 252
Feature Codes 253
Creating the Database Schema 254
Loading the Data 256
Creating a Java Object Model 257
Creating the Admin1Code Class 258
Creating the Admin2Code Class 261
Creating the Feature Codes Class 264
Creating the Place Class 267
Configuring Hibernate 271
Building the List of High Points 273
Developing the HQL Query 273
Running the Query 274
Moving Forward with the Example 276
Summary 276
APPENDIX A More Advanced Features 277
Managed Versioning and Optimistic Locking 277
Maps 278
Limitations of Hibernate 279
Hand-Rolled SQL 280
Using a Direct Mapping 280
Using a View 281
Putting SQL into an Annotation or Mapping 283
Invoking Stored Procedures 285
Events 286
An Example Event Listener 289
Interceptors 290
An Example Interceptor 293
Overriding the Default Constructor 298
Hibernate Search 299
Summary 300
APPENDIX B Hibernate Tools 301
The Eclipse Plug-In 301
Downloading the Hibernate Tools Plug-in 302
Installing the Plug-In 302
The Boilerplate Project Configuration 305
Using the Hibernate Console 307
Creating a Hibernate Console Configuration 308
Generating the Schema 311
Running the Test Program 312
Browsing the Model 312
Testing HQL Queries 314
Query Parameters 316
Creating a Mapping Diagram 317
Generating a Configuration File 318
The Reverse Engineering and Code Generation Tools 319
The Ant Tasks 327
How the Ant Tasks Work 327
Reverse Engineering 333
Templates 337
Configuring the Classpath 338
Summary 339
APPENDIX C Hibernate and Spring 340
Configuring Hibernate from a Spring Application 340
Configuring Spring 341
Using Hibernate in Your Spring Beans 343
Declarative Transaction Management 344
Managing the Session 345
The Sample Configuration File 346
Summary 349
APPENDIX D Upgrading from Hibernate 2 350
Package and DTD Changes 350
New Features and Support for Old Ones 351
Changes and Deprecated Features 352
Additions 353
Changes to Tools and Libraries 353
Changes with Java 5 354
Summary 354
Index 355

Erscheint lt. Verlag 30.6.2010
Zusatzinfo 400 p.
Verlagsort Berkeley
Sprache englisch
Themenwelt Mathematik / Informatik Informatik Programmiersprachen / -werkzeuge
Informatik Software Entwicklung Objektorientierung
Mathematik / Informatik Informatik Theorie / Studium
Mathematik / Informatik Informatik Web / Internet
Schlagworte Annotation • Hibernate • inform • Java • object • object-relational mapping • Spring Framework
ISBN-10 1-4302-2851-2 / 1430228512
ISBN-13 978-1-4302-2851-6 / 9781430228516
Haben Sie eine Frage zum Produkt?
PDFPDF (Wasserzeichen)
Größe: 5,0 MB

DRM: Digitales Wasserzeichen
Dieses eBook enthält ein digitales Wasser­zeichen und ist damit für Sie persona­lisiert. Bei einer missbräuch­lichen Weiter­gabe des eBooks an Dritte ist eine Rück­ver­folgung an die Quelle möglich.

Dateiformat: PDF (Portable Document Format)
Mit einem festen Seiten­layout eignet sich die PDF besonders für Fach­bücher mit Spalten, Tabellen und Abbild­ungen. Eine PDF kann auf fast allen Geräten ange­zeigt werden, ist aber für kleine Displays (Smart­phone, eReader) nur einge­schränkt geeignet.

Systemvoraussetzungen:
PC/Mac: Mit einem PC oder Mac können Sie dieses eBook lesen. Sie benötigen dafür einen PDF-Viewer - z.B. den Adobe Reader oder Adobe Digital Editions.
eReader: Dieses eBook kann mit (fast) allen eBook-Readern gelesen werden. Mit dem amazon-Kindle ist es aber nicht kompatibel.
Smartphone/Tablet: Egal ob Apple oder Android, dieses eBook können Sie lesen. Sie benötigen dafür einen PDF-Viewer - z.B. die kostenlose Adobe Digital Editions-App.

Zusätzliches Feature: Online Lesen
Dieses eBook können Sie zusätzlich zum Download auch online im Webbrowser lesen.

Buying eBooks from abroad
For tax law reasons we can sell eBooks just within Germany and Switzerland. Regrettably we cannot fulfill eBook-orders from other countries.

Mehr entdecken
aus dem Bereich
Entwicklung von GUIs für verschiedene Betriebssysteme

von Achim Lingott

eBook Download (2023)
Carl Hanser Verlag GmbH & Co. KG
39,99
Grundlagen, Objektorientierung und fortgeschrittene Konzepte

von Christian Kohls; Alexander Dobrynin

eBook Download (2023)
Carl Hanser Verlag GmbH & Co. KG
39,99