You are previewing Hibernate Recipes, Second Edition.
O'Reilly logo
Hibernate Recipes, Second Edition

Book Description

Hibernate Recipes, Second Edition contains a collection of code recipes and templates for learning and building Hibernate solutions for you and your clients, including how to work with the Spring Framework and the JPA. This book is your pragmatic day-to-day reference and guide for doing all things involving Hibernate. There are many books focused on learning Hibernate, but this book takes you further and shows how you can apply it practically in your daily work. Hibernate Recipes, Second Edition is a must have book for your library.

Hibernate 4.x continues to be the most popular out-of-the-box, open source framework solution for Java persistence and data/database accessibility techniques and patterns and it works well with the most popular open source enterprise Java framework of all, the Spring Framework. Hibernate is used for e-commerce–based web applications as well as heavy-duty transactional systems for the enterprise.

Table of Contents

  1. Cover
  2. Title
  3. Copyright
  4. Dedication
  5. Contents at a Glance
  6. Contents
  7. About the Authors
  8. About the Technical Reviewer
  9. Acknowledgments
  10. Chapter 1: Starting with Hibernate
    1. 1-1. Setting Up a Project
      1. Problem
      2. Solution
      3. How It Works
    2. 1-2. Setting Up a Database
      1. Problem
      2. Solution
      3. How It Works: Setting Up H2
      4. How It Works: Setting Up Derby
    3. 1-3. Configuring Hibernate
      1. Problem
      2. Solution
      3. How It Works
    4. 1-4. Using the JPA EntityManager
      1. Problem
      2. Solution
      3. How It Works
    5. 1-5. Enabling Logging in Hibernate
      1. Problem
      2. Solution
      3. How It Works
    6. Summary
  11. Chapter 2: Basic Mapping and Object Identity
    1. 2-0. Using JPA Annotations
      1. Problem
      2. Solution
      3. How It Works
    2. 2-1. Providing an ID for Persistence
      1. Problem
      2. Solution
      3. How It Works
    3. 2-2. Creating a Composite Key in Hibernate
      1. Problem
      2. Solution
      3. How It Works
    4. 2-3. saveOrUpdate() in Hibernate
      1. Problem
      2. Solution
      3. How It Works
    5. 2-4. Dynamic SQL Generation in Hibernate
      1. Problem
      2. Solution
      3. How It Works
    6. Summary
  12. Chapter 3: Component Mapping
    1. 3-1. Implementing a Value Type as a Component
      1. Problem
      2. Solution
      3. How It Works
      4. Using JPA Annotations
    2. 3-2. Nesting Components
      1. Problem
      2. Solution
      3. How It Works
    3. 3-3. Adding References in Components
      1. Problem
      2. Solution
      3. How It Works
    4. 3-4. Mapping a Collection of Components
      1. Problem
      2. Solution
      3. How It Works
    5. 3-5. Using Components as Keys to a Map
      1. Problem
      2. Solution
      3. How It Works
    6. Summary
  13. Chapter 4: Inheritance and Custom Mapping
    1. 4-1. Mapping Entities with Table per Class Hierarchy
      1. Problem
      2. Solution
      3. How It Works
    2. 4-2. Mapping Entities with Table per Subclass
      1. Problem
      2. Solution
      3. How It Works
    3. 4-3. Mapping Entities with Table per Concrete Class
      1. Problem
      2. Solution
      3. How It Works
    4. 4-4. Mapping Entities with Table per Class with a Mapped Superclass
      1. Problem
      2. Solution
      3. How It Works
    5. 4-5. Custom Mappings
      1. Problem
      2. Solution
      3. How It Works
    6. Summary
  14. Chapter 5: Many-to-One and One-to-One Mapping
    1. 5-1. Using Many-To-One Associations
      1. Problem
      2. Solution
      3. How It Works
    2. 5-2. Using a Many-to-One Association with a Join Table
      1. Problem
      2. Solution
      3. How It Works
    3. 5-3. Using Lazy Initialization on Many-to-One Associations
      1. Problem
      2. Solution
      3. How It Works
    4. 5-4. Creating a One-to-One Association Using a Foreign Key
      1. Problem
      2. Solution
      3. How It Works
    5. 5-5. Creating a One-to-One Association Using a Join Table
      1. Problem
      2. Solution
      3. How It Works
    6. Summary
  15. Chapter 6: Collection Mapping
    1. 6-1. Mapping a Set
      1. Problem
      2. Solution
      3. How It Works
    2. 6-2. Mapping a Bag
      1. Problem
      2. Solution
      3. How It Works
    3. 6-3. Mapping a List
      1. Problem
      2. Solution
      3. How It Works
    4. 6-4. Mapping an Array
      1. Problem
      2. Solution
      3. How It Works
    5. 6-5. Mapping a Map
      1. Problem
      2. Solution
      3. How It Works
    6. 6-6. Sorting Collections
      1. Problem
      2. Solution
      3. How It Works
    7. 6-7. Using Lazy Initialization
      1. Problem
      2. Solution
      3. How It Works
    8. Summary
  16. Chapter 7: Many-Valued Associations
    1. 7-1. Mapping a One-to-Many Association with a Foreign Key
      1. Problem
      2. Solution
      3. How It Works
    2. 7-2. Mapping a One-to-Many Bidirectional Association Using a Foreign Key
      1. Problem
      2. Solution
      3. How It Works
    3. 7-3. Mapping a One-to-Many Bidirectional Association Using a Join Table
      1. Problem
      2. Solution
      3. How It Works
    4. 7-4. Mapping a Many-to-Many Association with a Join Table
      1. Problem
      2. Solution
      3. How It Works
    5. Summary
  17. Chapter 8: HQL and JPA Query Language
    1. 8-1. Using the Query Object
      1. Problem
      2. Solution
      3. How It Works
    2. 8-2. Using the Select Clause
      1. Problem
      2. Solution
      3. How It Works
    3. 8-3. Joining
      1. Problem
      2. Solution
      3. How It Works
    4. 8-4. Creating Report Queries
      1. Problem
      2. Solution
      3. How It Works
    5. Summary
  18. Chapter 9: Querying with Criteria and Example
    1. 9-1. Using Criteria
      1. Problem
      2. Solution
      3. How It Works
    2. 9-2. Using Restrictions
      1. Problem
      2. Solution
      3. How It Works
    3. 9-3. Using Criteria in Associations
      1. Problem
      2. Solution
      3. How It Works
    4. 9-4. Using Projections
      1. Problem
      2. Solution
      3. How It Works
    5. 9-5. Querying by Example
      1. Problem
      2. Solution
      3. How It Works
    6. Summary
  19. Chapter 10: Working with Objects
    1. 10-1. Identifying Persistent Object States
      1. Problem
      2. Solution
      3. How It Works
    2. 10-2. Working with Persistent Objects
      1. Problem
      2. Solution
      3. How It Works
    3. 10-3. Persisting Detached Objects
      1. Problem
      2. Solution
      3. How It Works
    4. 10-4. Using Data Filters
      1. Problem
      2. Solution
      3. How It Works
    5. 10-5. Using Interceptors
      1. Problem
      2. Solution
      3. How It Works
    6. Summary
  20. Chapter 11: Batch Processing and Native SQL
    1. 11-1. Performing Batch Inserts
      1. Problem
      2. Solution
      3. How It Works
    2. 11-2. Performing Batch Updates and Deletes
      1. Problem
      2. Solution
      3. How It Works
    3. 11-3. Using Native SQL
      1. Problem
      2. Solution
      3. How It Works
    4. 11-4. Using Named SQL Queries
      1. Problem
      2. Solution
      3. How It Works
    5. Summary
  21. Chapter 12: Caching in Hibernate
    1. Using the Second-Level Cache in Hibernate
    2. Concurrency Strategies
    3. Cache Providers
    4. Cache Regions
    5. Caching Query Results
    6. 12-1. Using the First-Level Cache
      1. Problem
      2. Solution
      3. How It Works
    7. 12-2. Configuring the Second-Level Cache
      1. Problem
      2. Solution
      3. How It Works
    8. 12-3. Caching Associations
      1. Problem
      2. Solution
      3. How It Works
    9. 12-4. Caching Collections
      1. Problem
      2. Solution
      3. How It Works
    10. 12-5. Caching Queries
      1. Problem
      2. Solution
      3. How It Works
    11. Summary
  22. Chapter 13: Transactions and Concurrency
    1. 13-1. Using Programmatic Transactions in a Stand-alone Java Application
      1. Problem
      2. Solution
      3. How It Works
    2. 13-2. Using Programmatic Transactions with JTA
      1. Problem
      2. Solution
      3. How It Works
    3. 13-3. Enabling Optimistic Concurrency Control
      1. Problem
      2. Solution
      3. How It Works
    4. 13-4. Using Pessimistic Concurrency Control
      1. Problem
      2. Solution
      3. How It Works
    5. Summary
  23. Chapter 14: Web Applications
    1. What Is REST?
    2. 14-1. Exposing Persistence Over the Web
    3. Summary
  24. Index