Part1 Getting started with Hibernate and EJB 3.0 1 Understanding object/relational persistence 1.1 What is persistence? Relational databases Understanding SQL Using SQL in Java Persistence in object-oriented applications 1.2 The paradigm mismatch The problem of granularity The problem of subtypes The problem of identity Problems relating to associations The problem of data navigation The cost of the mismatch 1.3 Persistence layers and alternatives Layered architecture Hand-coding a persistence layer with SQL/JDBC Using serialization Object-oriented database systems Other options 1.4 Object/relational mapping What is ORM? Generic ORM problems Why ORM? Introducing Hibernate, EJB3, and JPA 1.5 Summary 2 Starting a project 2.1 Starting a Hibernate project Selecting a development process Setting up the project Hibernate configuration and startup Running and testing the application 2.2 Starting a Java Persistence project Using Hibernate Annotations Using Hibernate EntityManager Introducing EJB components Switching to Hibernate interfaces 2.3 Reverse engineering a legacy database Creating a database configuration Customizing reverse engineering Generating Java source code 2.4 Integration with Java EE services Integration with JTA JNDI-bound SessionFactory JMX service deployment 2.5 Summary 3 Domain models and metadata 3.1 The CaveatEmptor application Analyzing the business domain The CaveatEmptor domain model 3.2 Implementing the domain model Addressing leakage of concerns Transparent and automated persistence Writing POJOs and persistent entity classes Implementing POJO associations Adding logic to accessor methods 3.3 Object/relational mapping metadata Metadata in XML Annotation-based metadata Using XDoclet Handling global metadata Manipulating metadata at runtime 3.4 Alternative entity representation Creating dynamic applications Representing data in XML 3.5 Summary Part 2 Mapping concepts and strategies 4 Mapping persistent classes 4.1 Understanding entities and value types Fine-grained domain models Defining the concept Identifying entities and value types 4.2 Mapping entities with identity Understanding Java identity and equality Handling database identity Database primary keys 4.3 Class mapping options Dynamic SQL generation Making an entity immutable Naming entities for querying Declaring a package name Quoting SQL identifiers Implementing naming conventions 4.4 Fine-grained models and mappings Mapping basic properties Mapping components 4.5 Summary 5 Inheritance and custom types 5.1 Mapping class inheritance Table per concrete class with implicit polymorphism Table per concrete class with unions Table per class hierarchy Table per subclass Mixing inheritance strategies Choosing a strategy 5.2 The Hibernate type system Recapitulating entity and value types Built-in mapping types Using mapping types 5.3 Creating custom mapping types Considering custom mapping types The extension points The case for custom mapping types Creating a UserType Creating a CompositeUserType Parameterizing custom types Mapping enumerations 5.4 Summary 6 Mapping collections and entity associations 6.1 Sets, bags, lists, and maps of value types Selecting a collection interface Mapping a set Mapping an identifier bag Mapping a list Mapping a map Sorted and ordered collections 6.2 Collections of components Writing the component class Mapping the collection Enabling bidirectional navigation Avoiding not-null columns 6.3 Mapping collections with annotations Basic collection mapping Sorted and ordered collections Mapping a collection of embedded objects 6.4 Mapping a parent/children relationship Multiplicity The simplest possible association Making the association bidirectional Cascading object state 6.5 Summary 7 Advanced entity association mappings 7.1 Single-valued entity associations Shared primary key associations One-to-one foreign key associations Mapping with a join table 7.2 Many-valued entity associations One-to-many associations Many-to-many associations Adding columns to join tables Mapping maps 7.3 Polymorphic associations Polymorphic many-to-one associations Polymorphic collections Polymorphic associations to unions Polymorphic table per concrete class 7.4 Summary 8 Legacy databases and custom SQL 8.1 Integrating legacy databases Handling primary keys Arbitrary join conditions with formulas Joining arbitrary tables Working with triggers 8.2 Customizing SQL Writing custom CRUD statements Integrating stored procedures and functions 8.3 Improving schema DDL Custom SQL names and datatypes Ensuring data consistency Adding domains and column constraints Table-level constraints Database constraints Creating indexes Adding auxiliary DDL 8.4 Summary Part 3 Conversational object processing 9 Working with objects 9.1 The persistence lifecycle Object states The persistence context 9.2 Object identity and equality Introducing conversations The scope of object identity The identity of detached objects Extending a persistence context 9.3 The Hibernate interfaces Storing and loading objects Working with detached objects Managing the persistence context 9.4 The Java Persistence API Storing and loading objects Working with detached entity instances 9.5 Using Java Persistence in EJB components Injecting an EntityManager Looking up an EntityManager Accessing an EntityManagerFactory 9.6 Summary 10 Transactions and concurrency 10.1 Transaction essentials Database and system transactions Transactions in a Hibernate application Transactions with Java Persistence 10.2 Controlling concurrent access Understanding database-level concurrency Optimistic concurrency control Obtaining additional isolation guarantees 10.3 Nontransactional data access Debunking autocommit myths Working nontransactionally with Hibernate Optional transactions with JTA 10.4 Summary 11 Implementing conversations 11.1 Propagating the Hibernate Session The use case for Session propagation Propagation through thread-local Propagation with JTA Propagation with EJBs 11.2 Conversations with Hibernate Providing conversational guarantees Conversations with detached objects Extending a Session for a conversation 11.3 Conversations with JPA Persistence context propagation in Java SE Merging detached objects in conversations Extending the persistence context in Java SE 11.4 Conversations with EJB 3.0 Context propagation with EJBs Extended persistence contexts with EJBs 11.5 Summary 12 Modifying objects efficiently 12.1 Transitive persistence Persistence by reachability Applying cascading to associations Working with transitive state Transitive associations with JPA 12.2 Bulk and batch operations Bulk statements with HQL and JPA QL Processing with batches Using a stateless Session 12.3 Data filtering and interception Dynamic data filters Intercepting Hibernate events The core event system Entity listeners and callbacks 12.4 Summary 13 Optimizing fetching and caching 13.1 Defining the global fetch plan The object-retrieval options The lazy default fetch plan Understanding proxies Disabling proxy generation Eager loading of associations and collections Lazy loading with interception 13.2 Selecting a fetch strategy Prefetching data in batches Prefetching collections with subselects Eager fetching with joins Optimizing fetching for secondary tables Optimization guidelines 13.3 Caching fundamentals Caching strategies and scopes The Hibernate cache architecture 13.4 Caching in practice Selecting a concurrency control strategy Understanding cache regions Setting up a local cache provider Setting up a replicated cache Controlling the second-level cache 13.5 Summary 14 Querying with HQL and JPA QL 14.1 Creating and running queries Preparing a query Executing a query Using named queries 14.2 Basic HQL and JPA QL queries Selection Restriction Projection 14.3 Joins, reporting queries, and subselects Joining relations and associations Reporting queries Using subselects 14.4 Summary 15 Advanced query options 15.1 Querying with criteria and example Basic criteria queries Joins and dynamic fetching Projection and report queries Query by example 15.2 Using native SQL queries Automatic resultset handling Retrieving scalar values Native SQL in Java Persistence 15.3 Filtering collections 15.4 Caching query results Enabling the query result cache Understanding the query cache When to use the query cache Natural identifier cache lookups 15.5 Summary 16 Creating and testing layered applications 16.1 Hibernate in a web application Introducing the use case Writing a controller The Open Session in View pattern Designing smart domain models 16.2 Creating a persistence layer A generic data-access object pattern Implementing the generic CRUD interface Implementing entity DAOs Using data-access objects 16.3 Introducing the Command pattern The basic interfaces Executing command objects Variations of the Command pattern 16.4 Designing applications with EJB 3.0 Implementing a conversation with stateful beans Writing DAOs with EJBs Utilizing dependency injection 16.5 Testing Understanding different kinds of tests Introducing TestNG Testing the persistence layer Considering performance benchmarks 16.6 Summary 17 Introducing JBoss Seam 17.1 The Java EE 5.0 programming model Considering JavaServer Faces Considering EJB 3.0 Writing a web application with JSF and EJB 3.0 Analyzing the application 17.2 Improving the application with Seam Configuring Seam Binding pages to stateful Seam components Analyzing the Seam application 17.3 Understanding contextual components Writing the login page Creating the components Aliasing contextual variables Completing the login/logout feature 17.4 Validating user input Introducing Hibernate Validator Creating the registration page Internationalization with Seam 17.5 Simplifying persistence with Seam Implementing a conversation Letting Seam manage the persistence context 17.6 Summary appendix A SQL fundamentals appendix B Mapping quick reference references index