Pro JPA 2, Second Edition

Book description

Pro JPA 2, Second Edition introduces, explains, and demonstrates how to use the new Java Persistence API (JPA) 2.1 from the perspective of one of the specification creators. A one-of-a-kind resource, it provides both theoretical and extremely practical coverage of JPA usage for both beginning and advanced developers.

Authors Mike Keith and Merrick Schincariol take a hands–on approach, based on their wealth of experience and expertise, by giving examples to illustrate each concept of the API and showing how it is used in practice. The examples use a common model from an overriding sample application, giving readers a context from which to start and helping them to understand the examples within an already familiar domain. After completing the book, you will have a full understanding of JPA and be able to successfully code applications using its annotations and APIs. The book also serves as an excellent reference guide during initial and later JPA application experiences.

  • Hands-on examples for all aspects of the JPA specification

  • Expert insight about various aspects of the API and when they are useful

  • Portability hints to provide increased awareness of the potential for non–portable JPA code

  • What you'll learn

  • How to get started with enterprise applications using JPA 2.1

  • Simple and advanced object–relational mapping techiques

  • How to use the complete Entity Manager API

  • How to create queries using the query language (JP QL) and the Criteria API

  • Locking, concurrency, and other advanced concepts

  • How to use XML mapping files and descriptors

  • How to package and deploy your Java Persistence applications

  • How to test your Java Persistence applications

  • Who this book is for

    The book generally targets enterprise and persistence developers who fall in one of three categories:

  • Those who are new to persistence; we will offer an introduction to persistence and to the basic concepts so these readers can have solid base from which to become proficient at JPA.

  • Those who know and/or use existing ORM persistence products such as Hibernate or TopLink/EclipseLink.

  • Those who have already used JPA and want to learn about newer features introduced by JPA 2.1, or have a good reference book to consult when they develop JPA applications.

  • In general, we assume that the reader is knowledgeable with Java, SQL, and JDBC, and has a little knowledge of Java EE.

    Table of contents

    1. Title Page
    2. Dedication
    3. Contents at a Glance
    4. Contents
    5. About the Authors
    6. About the Technical Reviewer
    7. Acknowledgments
    8. CHAPTER 1: Introduction
      1. Relational Databases
      2. Object-Relational Mapping
      3. Java Support for Persistence
      4. Why Another Standard?
      5. The Java Persistence API
      6. Summary
    9. CHAPTER 2: Getting Started
      1. Entity Overview
      2. Entity Metadata
      3. Creating an Entity
      4. Entity Manager
      5. Putting It All Together
      6. Packaging It Up
      7. Summary
    10. CHAPTER 3: Enterprise Applications
      1. Application Component Models
      2. Session Beans
      3. Servlets
      4. Dependency Management and CDI
      5. CDI and Contextual Injection
      6. Transaction Management
      7. Putting It All Together
      8. Summary
    11. CHAPTER 4: Object-Relational Mapping
      1. Persistence Annotations
      2. Accessing Entity State
      3. Mapping to a Table
      4. Mapping Simple Types
      5. Mapping the Primary Key
      6. Relationships
      7. Embedded Objects
      8. Summary
    12. CHAPTER 5: Collection Mapping
      1. Relationships and Element Collections
      2. Using Different Collection Types
      3. Best Practices
      4. Summary
    13. CHAPTER 6: Entity Manager
      1. Persistence Contexts
      2. Entity Managers
      3. Transaction Management
      4. Choosing an Entity Manager
      5. Entity Manager Operations
      6. Synchronization with the Database
      7. Detachment and Merging
      8. Summary
    14. CHAPTER 7: Using Queries
      1. Java Persistence Query Language
      2. Defining Queries
      3. Parameter Types
      4. Executing Queries
      5. Bulk Update and Delete
      6. Query Hints
      7. Query Best Practices
      8. Summary
    15. CHAPTER 8: Query Language
      1. Introducing JP QL
      2. Select Queries
      3. Aggregate Queries
      4. Update Queries
      5. Delete Queries
      6. Summary
    16. CHAPTER 9: Criteria API
      1. Overview
      2. Building Criteria API Queries
      3. Bulk Update and Delete
      4. Strongly Typed Query Definitions
      5. Summary
    17. CHAPTER 10: Advanced Object-Relational Mapping
      1. Table and Column Names
      2. Converting Entity State
      3. Complex Embedded Objects
      4. Compound Primary Keys
      5. Derived Identifiers
      6. Advanced Mapping Elements
      7. Advanced Relationships
      8. Multiple Tables
      9. Inheritance
      10. Summary
    18. CHAPTER 11: Advanced Queries
      1. SQL Queries
      2. Entity Graphs
      3. Summary
    19. CHAPTER 12: Other Advanced Topics
      1. Lifecycle Callbacks
      2. Validation
      3. Concurrency
      4. Refreshing Entity State
      5. Locking
      6. Caching
      7. Utility Classes
      8. Summary
    20. CHAPTER 13: XML Mapping Files
      1. The Metadata Puzzle
      2. The Mapping File
      3. Summary
    21. CHAPTER 14: Packaging and Deployment
      1. Configuring Persistence Units
      2. Building and Deploying
      3. Outside the Server
      4. Schema Generation
      5. Summary
    22. CHAPTER 15: Testing
      1. Testing Enterprise Applications
      2. Unit Testing
      3. Integration Testing
      4. Best Practices
      5. Summary
    23. Index

    Product information

    • Title: Pro JPA 2, Second Edition
    • Author(s): Mike Keith, Merrick Schincariol
    • Release date: September 2013
    • Publisher(s): Apress
    • ISBN: 9781430249269