Spring Persistence with Hibernate -  Paul Fisher,  Brian D. Murphy

Spring Persistence with Hibernate (eBook)

eBook Download: PDF
2011 | 1st ed.
264 Seiten
Apress (Verlag)
978-1-4302-2633-8 (ISBN)
Systemvoraussetzungen
39,99 inkl. MwSt
  • Download sofort lieferbar
  • Zahlungsarten anzeigen

Persistence is an important set of techniques and technologies for accessing and transacting data, and ensuring that data is mobile regardless of specific applications and contexts. In Java development, persistence is a key factor in enterprise, e-commerce, and other transaction-oriented applications.

Today, the Spring framework is the leading out-of-the-box solution for enterprise Java developers; in it, you can find a number of Java Persistence solutions.

This book gets you rolling with fundamental Spring Framework 3 concepts and integrating persistence functionality into enterprise Java applications using Hibernate, the Java™ Persistence API (JPA) 2, and the Grails Object Relational Mapping tool, GORM.

  • Covers core Hibernate fundamentals, demonstrating how the framework can be best utilized within a Spring application context
  • Covers how to use and integrate JPA 2, found in the new Java EE 6 platform
  • Covers how to integrate and use the new Grails persistence engine, GORM


Paul Tepper Fisher first began working in technology at Johns Hopkins University, where he spent several years developing a distance learning application for neuroscience, while completing graduate school there. He has founded two technology start-ups: SmartPants Media, Inc., a software development company specializing in interactive multimedia technology; and dialmercury.com, which develops telephony applications using VoIP and Java. Paul was also manager of technology at Wired.com, where he lead the software development team for the on-line publications of Wired.com, webmonkey.com, and howto.wired.com, using Spring, Grails, and Java technology. Currently, Paul is director of engineering for a new music service at Lime Company, where he manages several development teams using agile methodologies. Comprised of client-side and server-side components developed using Java, the music service is designed for horizontal scalability and leverages cloud-computing to dynamically change the infrastructure size in response to load. You can read Paul s blog at http://www.paultepperfisher.com. Paul lives in Brooklyn, New York.
Persistence is an important set of techniques and technologies for accessing and transacting data, and ensuring that data is mobile regardless of specific applications and contexts. In Java development, persistence is a key factor in enterprise, e-commerce, and other transaction-oriented applications. Today, the Spring framework is the leading out-of-the-box solution for enterprise Java developers; in it, you can find a number of Java Persistence solutions.This book gets you rolling with fundamental Spring Framework 3 concepts and integrating persistence functionality into enterprise Java applications using Hibernate, the Java™ Persistence API (JPA) 2, and the Grails Object Relational Mapping tool, GORM. Covers core Hibernate fundamentals, demonstrating how the framework can be best utilized within a Spring application context Covers how to use and integrate JPA 2, found in the new Java EE 6 platform Covers how to integrate and use the new Grails persistence engine, GORM

Paul Tepper Fisher first began working in technology at Johns Hopkins University, where he spent several years developing a distance learning application for neuroscience, while completing graduate school there. He has founded two technology start-ups: SmartPants Media, Inc., a software development company specializing in interactive multimedia technology; and dialmercury.com, which develops telephony applications using VoIP and Java. Paul was also manager of technology at Wired.com, where he lead the software development team for the on-line publications of Wired.com, webmonkey.com, and howto.wired.com, using Spring, Grails, and Java technology. Currently, Paul is director of engineering for a new music service at Lime Company, where he manages several development teams using agile methodologies. Comprised of client-side and server-side components developed using Java, the music service is designed for horizontal scalability and leverages cloud-computing to dynamically change the infrastructure size in response to load. You can read Paul s blog at http://www.paultepperfisher.com. Paul lives in Brooklyn, New York.

Contents at a Glance 5
Table of Contents 6
About the Authors 13
About the Technical Reviewer 14
Acknowledgments 15
Preface 16
CHAPTER 1 Architecting Your Application with Spring, Hibernate, and Patterns 18
The Benefit of a Consistent Approach 18
The Significance of Dependency Injection 19
A Synergistic Partnership 19
The Story of Spring’s and Hibernate’s Success 20
A Better Approach for Integration 20
Best Practices for Architecting an Application 21
The Layers of a Persistence Tier 22
The Domain Model 22
The Data Access Object (DAO) Layer 23
The Service Facade 24
Leveraging Declarative Transactions 26
Understanding Aspect Oriented Programming (AOP) 26
Simplifying Transactions 27
The Benefit of Coding to Interfaces 27
Testing your Persistence Tier 27
Advanced Features and Performance Tuning 28
Hibernate-Search 28
Building a REST Web Service 28
Other Persistence Design Patterns 29
The Template Pattern 29
The Active-Record Pattern 31
Summary 32
CHAPTER 2 Spring Basics 34
Exploring Spring’s Architecture 35
The Application Context 35
Beans, Beans, the Magical Fruit 37
The Spring Life Cycle 37
Understanding Bean Scopes 39
Dependency Injection and Inversion of Control 41
Setter-Based Dependency Injection 41
Constructor-Based Dependency Injection 42
Instance Collaboration 43
Coding to Interfaces 44
Dependency Injection via Autowiring 45
@Annotation-Based Dependency Injection 46
Set It and Forget It! 47
Injecting Code Using AOP and Interceptors 48
Summary 49
CHAPTER 3 Basic Application Setup 50
Application Management with Maven 50
Managed Dependencies 50
Standard Directory Structure 52
POM Deconstruction 52
Spring Configuration 54
Namespace Support 55
Externalizing Property Configurations 55
Component Scanning 55
Import Statements 56
Database Integration 57
JDBC Support 57
Integration with JNDI 58
Web Application Configuration 60
Servlet Definition 61
Spring MVC 62
Summary 64
CHAPTER 4 Persistence with Hibernate 65
The Evolution of Database Persistence in Java 65
EJB, JDO, and JPA 66
How Hibernate Fits In 68
JPA Interface Hierarchy 68
The Art Gallery Domain Model and DAO Structure 70
An @Entity-Annotated POJO 71
Simplified DAO Pattern with Generics 72
The Life Cycle of a JPA Entity 78
JPA Configuration 80
Bare-Bones JPA Setup 80
Spring Integration 82
Summary 84
CHAPTER 5 Domain Model Fundamentals 85
Understanding Associations 85
Building the Domain Model 87
Convention over Configuration 90
Managing Entity Identifiers 91
Using Cascading Options to Establish Data Relationships 92
Adding Second-Level Caching 93
Using Polymorphism with Hibernate 94
Summary 100
CHAPTER 6 DAOs and Querying 101
A Basic Hibernate DAO Implementation 101
Building a DAO 102
Using Spring’s Hibernate Support Classes 103
Enabling Query Caching with the HibernateTemplate 104
Going Template-less 105
Querying in Hibernate 108
Loading an Entity 109
Querying for a Particular Type 109
Using Named Parameters 110
Querying Using Core Hibernate 111
Using Named Queries 112
Working with Polymorphic Queries 112
Persisting Data with Hibernate 113
Saving and Updating Data 113
Handling Binary Data 113
Understanding the Benefits of the Criteria API 114
Using the JPA 2.0 Criteria API 115
Summary 123
CHAPTER 7 Transaction Management 125
The Joy of ACID 126
Understanding Isolation Levels 127
Serializable 128
Repeatable Read 128
Read Committed 129
Read Uncommitted 129
Controlling ACID Reflux 129
Platform Transaction Management 130
Declarative Transaction Management 131
Transactional Annotations 131
Declarative Transactions via XML 135
Programmatic Transaction Management 136
Transactional Examples 137
Creating a Batch Application 137
Using Two Datasources 138
Summary 139
CHAPTER 8 Effective Testing 141
Unit, Integration, and Functional Testing 142
Using JUnit for Effective Testing 143
Unit Testing with Mocks 144
Spring Dependency Injection and Testing 148
Testing with a Database 150
Summary 152
CHAPTER 9 Best Practices and AdvancedTechniques 153
Lazy Loading Issues 153
The N+1 Selects Problem 153
Less Lazy Mappings 155
Batching for Performance 156
Lazy Initialization Exceptions 157
Now Open Late: Keeping EntityManager Open Past Its Bedtime 158
Applying the Open EntityManager Filter 159
Caching 159
Integrating a Caching Implementation 160
Determining Caching Rules 162
Configuring Cache Regions 163
Caching Your Queries 165
Caching in a Clustered Configuration 166
Cluster Caching and Replication Mechanics 167
Configuring Replication 167
Summary 169
CHAPTER 10 Integration Frameworks 171
RESTful Web Services with Spring 171
Nouns, Verbs, and Content-Types 172
Serializing the Object Graph 173
Using the Dreaded DTO Pattern 174
Bootstrapping Dozer 175
Building the DTO Layer 175
Configuring Dozer with Spring 180
Making the Mapping Happen 183
Leveraging Spring 3’s REST Support 184
Marshaling Data with Spring OXM 186
Handling Concurrency 188
Optimistic Locking 188
Pessimistic Locking 188
Free-Text Search 189
Introducing Lucene 190
Indexing with Lucene 190
Querying with Lucene 191
Introducing Hibernate Search 192
Integrating Hibernate Search 193
Adding Hibernate Search Annotations 194
Putting Lucene and Hibernate in Sync 200
Building a Domain-Specific Search 201
Summary 202
CHAPTER 11 GORM and Grails 204
A Crash Course in Groovy 204
Letting Your Types Loose 206
GStrings—Strings on Steroids 206
Default Constructors in Groovy 206
Closures in Groovy 206
Getting Grails Running 208
Installing Grails 208
Creating a Grails Application 208
Configuring Your Application 211
Configuring Your Datasource 212
Mapping URLs 213
Defining the Grails Domain Model 214
Adding Constraints and Validation 215
Defining Associations and Properties 216
Customizing Domain Class Hibernate Mappings 218
Using Active Record As an Alternative to DAOs 219
Looking Under the Hood of GORM 220
Working with Dynamic Finder Methods 220
Creating Advanced Query Methods 225
Using the Criteria API 225
Handling Associations in Grails 226
Scaffolding and Building Your Grails Application 227
Defining a Transactional Service Layer in Grails 228
Summary 229
CHAPTER 12 Spring Roo 230
What Roo Is (and What It Is Not) 230
Creating a Domain Model with Roo 232
Getting Started with Roo 233
Creating a New Project 235
Adding Entities 236
Adding Fields 240
Exploring the Automatically Generated Testing Infrastructure 241
Mapping Associations 243
Modeling Inheritance 243
Adding Spring MVC 245
Adding Service Layers and DAOs 246
Now You See Me, Now You Don’t—Removing Roo 248
Summary 249
Index 250

Erscheint lt. Verlag 1.2.2011
Zusatzinfo 264 p.
Verlagsort Berkeley
Sprache englisch
Themenwelt Mathematik / Informatik Informatik Programmiersprachen / -werkzeuge
Mathematik / Informatik Informatik Theorie / Studium
Mathematik / Informatik Informatik Web / Internet
Schlagworte Development • E-Commerce • Framework • Grails • Java • Java EE • Management • techniques • Technology
ISBN-10 1-4302-2633-1 / 1430226331
ISBN-13 978-1-4302-2633-8 / 9781430226338
Haben Sie eine Frage zum Produkt?
Wie bewerten Sie den Artikel?
Bitte geben Sie Ihre Bewertung ein:
Bitte geben Sie Daten ein:
PDFPDF (Wasserzeichen)
Größe: 2,3 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
Das Handbuch für Webentwickler

von Philip Ackermann

eBook Download (2023)
Rheinwerk Computing (Verlag)
49,90