E-Book, Englisch, 264 Seiten
Fisher / Murphy Spring Persistence with Hibernate
1. ed
ISBN: 978-1-4302-2633-8
Verlag: Apress
Format: PDF
Kopierschutz: 1 - PDF Watermark
E-Book, Englisch, 264 Seiten
ISBN: 978-1-4302-2633-8
Verlag: Apress
Format: PDF
Kopierschutz: 1 - PDF Watermark
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.
Autoren/Hrsg.
Weitere Infos & Material
1;Contents at a Glance;5
2;Table of Contents;6
3;About the Authors;13
4;About the Technical Reviewer;14
5;Acknowledgments;15
6;Preface;16
7;CHAPTER 1 Architecting Your Application with Spring, Hibernate, and Patterns;18
7.1;The Benefit of a Consistent Approach;18
7.1.1;The Significance of Dependency Injection;19
7.2;A Synergistic Partnership;19
7.2.1;The Story of Spring’s and Hibernate’s Success;20
7.2.2;A Better Approach for Integration;20
7.2.3;Best Practices for Architecting an Application;21
7.2.3.1;The Layers of a Persistence Tier;22
7.2.3.1.1;The Domain Model;22
7.2.3.1.2;The Data Access Object (DAO) Layer;23
7.2.3.1.3;The Service Facade;24
7.2.3.2;Leveraging Declarative Transactions;26
7.2.3.2.1;Understanding Aspect Oriented Programming (AOP);26
7.2.3.2.2;Simplifying Transactions;27
7.2.3.2.3;The Benefit of Coding to Interfaces;27
7.2.3.2.3.1;Testing your Persistence Tier;27
7.2.3.3;Advanced Features and Performance Tuning;28
7.2.3.3.1;Hibernate-Search;28
7.2.3.3.2;Building a REST Web Service;28
7.3;Other Persistence Design Patterns;29
7.3.1;The Template Pattern;29
7.3.2;The Active-Record Pattern;31
7.4;Summary;32
8;CHAPTER 2 Spring Basics;34
8.1;Exploring Spring’s Architecture;35
8.1.1;The Application Context;35
8.1.2;Beans, Beans, the Magical Fruit;37
8.1.3;The Spring Life Cycle;37
8.1.4;Understanding Bean Scopes;39
8.2;Dependency Injection and Inversion of Control;41
8.2.1;Setter-Based Dependency Injection;41
8.2.2;Constructor-Based Dependency Injection;42
8.2.3;Instance Collaboration;43
8.2.4;Coding to Interfaces;44
8.2.5;Dependency Injection via Autowiring;45
8.2.6;@Annotation-Based Dependency Injection;46
8.2.7;Set It and Forget It!;47
8.3;Injecting Code Using AOP and Interceptors;48
8.4;Summary;49
9;CHAPTER 3 Basic Application Setup;50
9.1;Application Management with Maven;50
9.1.1;Managed Dependencies;50
9.1.2;Standard Directory Structure;52
9.1.3;POM Deconstruction;52
9.2;Spring Configuration;54
9.2.1;Namespace Support;55
9.2.2;Externalizing Property Configurations;55
9.2.3;Component Scanning;55
9.2.4;Import Statements;56
9.3;Database Integration;57
9.3.1;JDBC Support;57
9.3.2;Integration with JNDI;58
9.4;Web Application Configuration;60
9.4.1;Servlet Definition;61
9.4.2;Spring MVC;62
9.5;Summary;64
10;CHAPTER 4 Persistence with Hibernate;65
10.1;The Evolution of Database Persistence in Java;65
10.1.1;EJB, JDO, and JPA;66
10.1.2;How Hibernate Fits In;68
10.2;JPA Interface Hierarchy;68
10.3;The Art Gallery Domain Model and DAO Structure;70
10.3.1;An @Entity-Annotated POJO;71
10.3.2;Simplified DAO Pattern with Generics;72
10.3.3;The Life Cycle of a JPA Entity;78
10.4;JPA Configuration;80
10.4.1;Bare-Bones JPA Setup;80
10.4.2;Spring Integration;82
10.5;Summary;84
11;CHAPTER 5 Domain Model Fundamentals;85
11.1;Understanding Associations;85
11.2;Building the Domain Model;87
11.2.1;Convention over Configuration;90
11.2.2;Managing Entity Identifiers;91
11.2.3;Using Cascading Options to Establish Data Relationships;92
11.2.4;Adding Second-Level Caching;93
11.2.5;Using Polymorphism with Hibernate;94
11.3;Summary;100
12;CHAPTER 6 DAOs and Querying;101
12.1;A Basic Hibernate DAO Implementation;101
12.1.1;Building a DAO;102
12.1.2;Using Spring’s Hibernate Support Classes;103
12.1.3;Enabling Query Caching with the HibernateTemplate;104
12.1.4;Going Template-less;105
12.2;Querying in Hibernate;108
12.2.1;Loading an Entity;109
12.2.2;Querying for a Particular Type;109
12.2.3;Using Named Parameters;110
12.2.4;Querying Using Core Hibernate;111
12.2.5;Using Named Queries;112
12.2.6;Working with Polymorphic Queries;112
12.3;Persisting Data with Hibernate;113
12.3.1;Saving and Updating Data;113
12.3.2;Handling Binary Data;113
12.3.3;Understanding the Benefits of the Criteria API;114
12.3.4;Using the JPA 2.0 Criteria API;115
12.4;Summary;123
13;CHAPTER 7 Transaction Management;125
13.1;The Joy of ACID;126
13.2;Understanding Isolation Levels;127
13.2.1;Serializable;128
13.2.2;Repeatable Read;128
13.2.3;Read Committed;129
13.2.4;Read Uncommitted;129
13.3;Controlling ACID Reflux;129
13.3.1;Platform Transaction Management;130
13.3.2;Declarative Transaction Management;131
13.3.2.1;Transactional Annotations;131
13.3.2.2;Declarative Transactions via XML;135
13.3.3;Programmatic Transaction Management;136
13.4;Transactional Examples;137
13.4.1;Creating a Batch Application;137
13.4.2;Using Two Datasources;138
13.5;Summary;139
14;CHAPTER 8 Effective Testing;141
14.1;Unit, Integration, and Functional Testing;142
14.2;Using JUnit for Effective Testing;143
14.2.1;Unit Testing with Mocks;144
14.2.2;Spring Dependency Injection and Testing;148
14.2.3;Testing with a Database;150
14.3;Summary;152
15;CHAPTER 9 Best Practices and AdvancedTechniques;153
15.1;Lazy Loading Issues;153
15.1.1;The N+1 Selects Problem;153
15.1.1.1;Less Lazy Mappings;155
15.1.1.2;Batching for Performance;156
15.1.2;Lazy Initialization Exceptions;157
15.1.2.1;Now Open Late: Keeping EntityManager Open Past Its Bedtime;158
15.1.2.2;Applying the Open EntityManager Filter;159
15.2;Caching;159
15.2.1;Integrating a Caching Implementation;160
15.2.1.1;Determining Caching Rules;162
15.2.1.2;Configuring Cache Regions;163
15.2.2;Caching Your Queries;165
15.2.3;Caching in a Clustered Configuration;166
15.2.3.1;Cluster Caching and Replication Mechanics;167
15.2.3.2;Configuring Replication;167
15.3;Summary;169
16;CHAPTER 10 Integration Frameworks;171
16.1;RESTful Web Services with Spring;171
16.1.1;Nouns, Verbs, and Content-Types;172
16.1.2;Serializing the Object Graph;173
16.1.3;Using the Dreaded DTO Pattern;174
16.1.3.1;Bootstrapping Dozer;175
16.1.3.2;Building the DTO Layer;175
16.1.3.3;Configuring Dozer with Spring;180
16.1.3.4;Making the Mapping Happen;183
16.1.4;Leveraging Spring 3’s REST Support;184
16.1.5;Marshaling Data with Spring OXM;186
16.1.6;Handling Concurrency;188
16.1.6.1;Optimistic Locking;188
16.1.6.2;Pessimistic Locking;188
16.2;Free-Text Search;189
16.2.1;Introducing Lucene;190
16.2.1.1;Indexing with Lucene;190
16.2.1.2;Querying with Lucene;191
16.2.2;Introducing Hibernate Search;192
16.2.2.1;Integrating Hibernate Search;193
16.2.2.2;Adding Hibernate Search Annotations;194
16.2.3;Putting Lucene and Hibernate in Sync;200
16.2.4;Building a Domain-Specific Search;201
16.3;Summary;202
17;CHAPTER 11 GORM and Grails;204
17.1;A Crash Course in Groovy;204
17.1.1;Letting Your Types Loose;206
17.1.2;GStrings—Strings on Steroids;206
17.1.3;Default Constructors in Groovy;206
17.1.4;Closures in Groovy;206
17.2;Getting Grails Running;208
17.2.1;Installing Grails;208
17.2.2;Creating a Grails Application;208
17.2.3;Configuring Your Application;211
17.2.4;Configuring Your Datasource;212
17.2.5;Mapping URLs;213
17.3;Defining the Grails Domain Model;214
17.3.1;Adding Constraints and Validation;215
17.3.2;Defining Associations and Properties;216
17.3.3;Customizing Domain Class Hibernate Mappings;218
17.4;Using Active Record As an Alternative to DAOs;219
17.5;Looking Under the Hood of GORM;220
17.5.1;Working with Dynamic Finder Methods;220
17.5.2;Creating Advanced Query Methods;225
17.5.3;Using the Criteria API;225
17.6;Handling Associations in Grails;226
17.7;Scaffolding and Building Your Grails Application;227
17.8;Defining a Transactional Service Layer in Grails;228
17.9;Summary;229
18;CHAPTER 12 Spring Roo;230
18.1;What Roo Is (and What It Is Not);230
18.2;Creating a Domain Model with Roo;232
18.2.1;Getting Started with Roo;233
18.2.2;Creating a New Project;235
18.2.3;Adding Entities;236
18.2.4;Adding Fields;240
18.2.5;Exploring the Automatically Generated Testing Infrastructure;241
18.2.6;Mapping Associations;243
18.2.7;Modeling Inheritance;243
18.2.8;Adding Spring MVC;245
18.2.9;Adding Service Layers and DAOs;246
18.3;Now You See Me, Now You Don’t—Removing Roo;248
18.4;Summary;249
19;Index;250




