Pro JPA 2: Mastering the Java™ Persistence API

Book description

Pro JPA 2 introduces, explains, and demonstrates how to use the new Java Persistence API (JPA). JPA provides Java developers with both the knowledge and insight needed to write Java applications that access relational databases through JPA. Authors Mike Keith and Merrick Schincariol take a hands-on approach to teaching by giving examples to illustrate each new concept of the API and showing how it is used in practice.

Table of contents

  1. Copyright
  2. Foreword
  3. About the Author
  4. About the Technical Reviewer
  5. Acknowledgments
    1. Mike Keith
    2. Merrick Schincariol
  6. Preface
    1. This Book Is For You
    2. Code Examples
    3. Contacting Us
  7. 1. Introduction
    1. 1.1. Object-Relational Mapping
      1. 1.1.1. The Impedance Mismatch
        1. 1.1.1.1. Class Representation
        2. 1.1.1.2. Relationships
        3. 1.1.1.3. Inheritance
    2. 1.2. Java Support for Persistence
      1. 1.2.1. Proprietary Solutions
      2. 1.2.2. JDBC
      3. 1.2.3. Enterprise JavaBeans
      4. 1.2.4. Java Data Objects
    3. 1.3. Why Another Standard?
    4. 1.4. The Java Persistence API
      1. 1.4.1. History of the Specification
        1. 1.4.1.1. EJB 3.0 and JPA 1.0
        2. 1.4.1.2. JPA 2.0
        3. 1.4.1.3. JPA and You
      2. 1.4.2. Overview
        1. 1.4.2.1. POJO Persistence
        2. 1.4.2.2. Nonintrusiveness
        3. 1.4.2.3. Object Queries
        4. 1.4.2.4. Mobile Entities
        5. 1.4.2.5. Simple Configuration
        6. 1.4.2.6. Integration and Testability
    5. 1.5. Summary
  8. 2. Getting Started
    1. 2.1. Entity Overview
      1. 2.1.1. Persistability
      2. 2.1.2. Identity
      3. 2.1.3. Transactionality
      4. 2.1.4. Granularity
    2. 2.2. Entity Metadata
      1. 2.2.1. Annotations
      2. 2.2.2. XML
      3. 2.2.3. Configuration by Exception
    3. 2.3. Creating an Entity
    4. 2.4. Entity Manager
      1. 2.4.1. Obtaining an Entity Manager
      2. 2.4.2. Persisting an Entity
      3. 2.4.3. Finding an Entity
      4. 2.4.4. Removing an Entity
      5. 2.4.5. Updating an Entity
      6. 2.4.6. Transactions
      7. 2.4.7. Queries
    5. 2.5. Putting It All Together
    6. 2.6. Packaging It Up
      1. 2.6.1. Persistence Unit
      2. 2.6.2. Persistence Archive
    7. 2.7. Summary
  9. 3. Enterprise Applications
    1. 3.1. Application Component Models
    2. 3.2. Session Beans
      1. 3.2.1. Stateless Session Beans
        1. 3.2.1.1. Defining a Stateless Session Bean
        2. 3.2.1.2. Lifecycle Callbacks
        3. 3.2.1.3. Remote Business Interfaces
      2. 3.2.2. Stateful Session Beans
        1. 3.2.2.1. Defining a Stateful Session Bean
        2. 3.2.2.2. Lifecycle Callbacks
      3. 3.2.3. Singleton Session Beans
        1. 3.2.3.1. Defining a Singleton Session Bean
        2. 3.2.3.2. Lifecycle Callbacks
        3. 3.2.3.3. Singleton Concurrency
    3. 3.3. Message-Driven Beans
      1. 3.3.1. Defining a Message-Driven Bean
    4. 3.4. Servlets
    5. 3.5. Dependency Management
      1. 3.5.1. Dependency Lookup
      2. 3.5.2. Dependency Injection
        1. 3.5.2.1. Field Injection
        2. 3.5.2.2. Setter Injection
      3. 3.5.3. Declaring Dependencies
        1. 3.5.3.1. Referencing a Persistence Context
        2. 3.5.3.2. Referencing a Persistence Unit
        3. 3.5.3.3. Referencing Enterprise JavaBeans
        4. 3.5.3.4. Referencing Server Resources
    6. 3.6. Transaction Management
      1. 3.6.1. Transaction Review
      2. 3.6.2. Enterprise Transactions in Java
        1. 3.6.2.1. Transaction Demarcation
        2. 3.6.2.2. Container-Managed Transactions
        3. 3.6.2.3. Bean-Managed Transactions
          1. 3.6.2.3.1. UserTransaction
    7. 3.7. Using Java EE Components
      1. 3.7.1. Using a Stateless Session Bean
      2. 3.7.2. Using a Stateful Session Bean
      3. 3.7.3. Using a Singleton Session Bean
      4. 3.7.4. Using a Message-Driven Bean
      5. 3.7.5. Adding the Entity Manager
    8. 3.8. Putting It All Together
      1. 3.8.1. Defining the Component
      2. 3.8.2. Defining the User Interface
      3. 3.8.3. Packaging It Up
    9. 3.9. Summary
  10. 4. Object-Relational Mapping
    1. 4.1. Persistence Annotations
    2. 4.2. Accessing Entity State
      1. 4.2.1. Field Access
      2. 4.2.2. Property Access
      3. 4.2.3. Mixed Access
    3. 4.3. Mapping to a Table
    4. 4.4. Mapping Simple Types
      1. 4.4.1. Column Mappings
      2. 4.4.2. Lazy Fetching
      3. 4.4.3. Large Objects
      4. 4.4.4. Enumerated Types
      5. 4.4.5. Temporal Types
      6. 4.4.6. Transient State
    5. 4.5. Mapping the Primary Key
      1. 4.5.1. Overriding the Primary Key Column
      2. 4.5.2. Primary Key Types
      3. 4.5.3. Identifier Generation
        1. 4.5.3.1. Automatic Id Generation
        2. 4.5.3.2. Id Generation Using a Table
        3. 4.5.3.3. Id Generation Using a Database Sequence
        4. 4.5.3.4. Id Generation Using Database Identity
    6. 4.6. Relationships
      1. 4.6.1. Relationship Concepts
        1. 4.6.1.1. Roles
        2. 4.6.1.2. Directionality
        3. 4.6.1.3. Cardinality
        4. 4.6.1.4. Ordinality
      2. 4.6.2. Mappings Overview
      3. 4.6.3. Single-Valued Associations
        1. 4.6.3.1. Many-to-One Mappings
        2. 4.6.3.2. Using Join Columns
        3. 4.6.3.3. One-to-One Mappings
        4. 4.6.3.4. Bidirectional One-to-One Mappings
      4. 4.6.4. Collection-Valued Associations
        1. 4.6.4.1. One-to-Many Mappings
        2. 4.6.4.2. Many-to-Many Mappings
        3. 4.6.4.3. Using Join Tables
        4. 4.6.4.4. Unidirectional Collection Mappings
      5. 4.6.5. Lazy Relationships
    7. 4.7. Embedded Objects
    8. 4.8. Summary
  11. 5. Collection Mapping
    1. 5.1. Relationships and Element Collections
    2. 5.2. Using Different Collection Types
      1. 5.2.1. Sets or Collections
      2. 5.2.2. Lists
        1. 5.2.2.1. Ordering By Entity or Element Attribute
        2. 5.2.2.2. Persistently Ordered Lists
      3. 5.2.3. Maps
        1. 5.2.3.1. Keys and Values
        2. 5.2.3.2. Keying By Basic Type
        3. 5.2.3.3. Keying by Entity Attribute
        4. 5.2.3.4. Keying by Embeddable Type
          1. 5.2.3.4.1. Sharing Embeddable Key Mappings with Values
          2. 5.2.3.4.2. Overriding Embeddable Attributes
        5. 5.2.3.5. Keying by Entity
        6. 5.2.3.6. Untyped Maps
        7. 5.2.3.7. Rules for Maps
      4. 5.2.4. Duplicates
      5. 5.2.5. Null Values
    3. 5.3. Best Practices
    4. 5.4. Summary
  12. 6. Entity Manager
    1. 6.1. Persistence Contexts
    2. 6.2. Entity Managers
      1. 6.2.1. Container-Managed Entity Managers
        1. 6.2.1.1. Transaction-Scoped
        2. 6.2.1.2. Extended
      2. 6.2.2. Application-Managed Entity Managers
    3. 6.3. Transaction Management
      1. 6.3.1. JTA Transaction Management
        1. 6.3.1.1. Transaction-Scoped Persistence Contexts
        2. 6.3.1.2. Extended Persistence Contexts
          1. 6.3.1.2.1. Persistence Context Collision
          2. 6.3.1.2.2. Persistence Context Inheritance
        3. 6.3.1.3. Application-Managed Persistence Contexts
      2. 6.3.2. Resource-Local Transactions
      3. 6.3.3. Transaction Rollback and Entity State
    4. 6.4. Choosing an Entity Manager
    5. 6.5. Entity Manager Operations
      1. 6.5.1. Persisting an Entity
      2. 6.5.2. Finding an Entity
      3. 6.5.3. Removing an Entity
      4. 6.5.4. Cascading Operations
        1. 6.5.4.1. Cascade Persist
        2. 6.5.4.2. Cascade Remove
      5. 6.5.5. Clearing the Persistence Context
    6. 6.6. Synchronization with the Database
    7. 6.7. Detachment and Merging
      1. 6.7.1. Detachment
      2. 6.7.2. Merging Detached Entities
      3. 6.7.3. Working with Detached Entities
        1. 6.7.3.1. Planning for Detachment
          1. 6.7.3.1.1. Triggering Lazy Loading
          2. 6.7.3.1.2. Configuring Eager Loading
        2. 6.7.3.2. Avoiding Detachment
          1. 6.7.3.2.1. Transaction View
          2. 6.7.3.2.2. Entity Manager per Request
        3. 6.7.3.3. Merge Strategies
          1. 6.7.3.3.1. Session Façade
          2. 6.7.3.3.2. Edit Session
    8. 6.8. Summary
  13. 7. Using Queries
    1. 7.1. Java Persistence Query Language
      1. 7.1.1. Getting Started
      2. 7.1.2. Filtering Results
      3. 7.1.3. Projecting Results
      4. 7.1.4. Joins Between Entities
      5. 7.1.5. Aggregate Queries
      6. 7.1.6. Query Parameters
    2. 7.2. Defining Queries
      1. 7.2.1. Dynamic Query Definition
      2. 7.2.2. Named Query Definition
    3. 7.3. Parameter Types
    4. 7.4. Executing Queries
      1. 7.4.1. Working with Query Results
        1. 7.4.1.1. Untyped Results
        2. 7.4.1.2. Optimizing Read-Only Queries
        3. 7.4.1.3. Special Result Types
      2. 7.4.2. Query Paging
      3. 7.4.3. Queries and Uncommitted Changes
      4. 7.4.4. Query Timeouts
    5. 7.5. Bulk Update and Delete
      1. 7.5.1. Using Bulk Update and Delete
      2. 7.5.2. Bulk Delete and Relationships
    6. 7.6. Query Hints
    7. 7.7. Query Best Practices
      1. 7.7.1. Named Queries
      2. 7.7.2. Report Queries
      3. 7.7.3. Vendor Hints
      4. 7.7.4. Stateless Session Beans
      5. 7.7.5. Bulk Update and Delete
      6. 7.7.6. Provider Differences
    8. 7.8. Summary
  14. 8. Query Language
    1. 8.1. Introduction
      1. 8.1.1. Terminology
      2. 8.1.2. Example Data Model
      3. 8.1.3. Example Application
    2. 8.2. Select Queries
      1. 8.2.1. SELECT Clause
        1. 8.2.1.1. Path Expressions
        2. 8.2.1.2. Entities and Objects
        3. 8.2.1.3. Combining Expressions
        4. 8.2.1.4. Constructor Expressions
        5. 8.2.1.5. Inheritance and Polymorphism
      2. 8.2.2. FROM Clause
        1. 8.2.2.1. Identification Variables
        2. 8.2.2.2. Joins
          1. 8.2.2.2.1. Inner Joins
          2. 8.2.2.2.2. JOIN Operator and Collection Association Fields
          3. 8.2.2.2.3. JOIN Operator and Single-Valued Association Fields
          4. 8.2.2.2.4. Join Conditions in the WHERE Clause
          5. 8.2.2.2.5. Multiple Joins
          6. 8.2.2.2.6. Map Joins
          7. 8.2.2.2.7. Outer Joins
          8. 8.2.2.2.8. Fetch Joins
      3. 8.2.3. WHERE Clause
        1. 8.2.3.1. Input Parameters
        2. 8.2.3.2. Basic Expression Form
        3. 8.2.3.3. BETWEEN Expressions
        4. 8.2.3.4. LIKE Expressions
        5. 8.2.3.5. Subqueries
        6. 8.2.3.6. IN Expressions
        7. 8.2.3.7. Collection Expressions
        8. 8.2.3.8. EXISTS Expressions
        9. 8.2.3.9. ANY, ALL, and SOME Expressions
      4. 8.2.4. Scalar Expressions
        1. 8.2.4.1. Literals
        2. 8.2.4.2. Function Expressions
        3. 8.2.4.3. CASE Expressions
      5. 8.2.5. ORDER BY Clause
    3. 8.3. Aggregate Queries
      1. 8.3.1. Aggregate Functions
        1. 8.3.1.1. AVG
        2. 8.3.1.2. COUNT
        3. 8.3.1.3. MAX
        4. 8.3.1.4. MIN
        5. 8.3.1.5. SUM
      2. 8.3.2. GROUP BY Clause
      3. 8.3.3. HAVING Clause
    4. 8.4. Update Queries
    5. 8.5. Delete Queries
    6. 8.6. Summary
  15. 9. Criteria API
    1. 9.1. Overview
      1. 9.1.1. The Criteria API
      2. 9.1.2. Parameterized Types
      3. 9.1.3. Dynamic Queries
    2. 9.2. Building Criteria API Queries
      1. 9.2.1. Creating a Query Definition
      2. 9.2.2. Basic Structure
      3. 9.2.3. Criteria Objects and Mutability
      4. 9.2.4. Query Roots and Path Expressions
        1. 9.2.4.1. Query Roots
        2. 9.2.4.2. Path Expressions
      5. 9.2.5. The SELECT Clause
        1. 9.2.5.1. Selecting Single Expressions
        2. 9.2.5.2. Selecting Multiple Expressions
        3. 9.2.5.3. Using Aliases
      6. 9.2.6. The FROM Clause
        1. 9.2.6.1. Inner and Outer Joins
        2. 9.2.6.2. Fetch Joins
      7. 9.2.7. The WHERE Clause
      8. 9.2.8. Building Expressions
        1. 9.2.8.1. Predicates
        2. 9.2.8.2. Literals
        3. 9.2.8.3. Parameters
        4. 9.2.8.4. Subqueries
        5. 9.2.8.5. In Expressions
        6. 9.2.8.6. Case Expressions
        7. 9.2.8.7. Function Expressions
      9. 9.2.9. The ORDER BY Clause
      10. 9.2.10. The GROUP BY and HAVING Clauses
    3. 9.3. Strongly Typed Query Definitions
      1. 9.3.1. The Metamodel API
      2. 9.3.2. Strongly Typed API Overview
      3. 9.3.3. The Canonical Metamodel
        1. 9.3.3.1. Using the Canonical Metamodel
        2. 9.3.3.2. Generating the Canonical Metamodel
      4. 9.3.4. Choosing the Right Type of Query
    4. 9.4. Summary
  16. 10. Advanced Object-Relational Mapping
    1. 10.1. Table and Column Names
    2. 10.2. Complex Embedded Objects
      1. 10.2.1. Advanced Embedded Mappings
      2. 10.2.2. Overriding Embedded Relationships
    3. 10.3. Compound Primary Keys
      1. 10.3.1. Id Class
      2. 10.3.2. Embedded Id Class
    4. 10.4. Derived Identifiers
      1. 10.4.1. Basic Rules for Derived Identifiers
      2. 10.4.2. Shared Primary Key
      3. 10.4.3. Multiple Mapped Attributes
      4. 10.4.4. Using EmbeddedId
    5. 10.5. Advanced Mapping Elements
      1. 10.5.1. Read-Only Mappings
      2. 10.5.2. Optionality
    6. 10.6. Advanced Relationships
      1. 10.6.1. Using Join Tables
      2. 10.6.2. Avoiding Join Tables
      3. 10.6.3. Compound Join Columns
      4. 10.6.4. Orphan Removal
      5. 10.6.5. Mapping Relationship State
    7. 10.7. Multiple Tables
    8. 10.8. Inheritance
      1. 10.8.1. Class Hierarchies
        1. 10.8.1.1. Mapped Superclasses
        2. 10.8.1.2. Transient Classes in the Hierarchy
        3. 10.8.1.3. Abstract and Concrete Classes
      2. 10.8.2. Inheritance Models
        1. 10.8.2.1. Single-Table Strategy
          1. 10.8.2.1.1. Discriminator Column
          2. 10.8.2.1.2. Discriminator Value
        2. 10.8.2.2. Joined Strategy
        3. 10.8.2.3. Table-per-Concrete-Class Strategy
      3. 10.8.3. Mixed Inheritance
    9. 10.9. Summary
  17. 11. Advanced Topics
    1. 11.1. SQL Queries
      1. 11.1.1. Native Queries versus JDBC
      2. 11.1.2. Defining and Executing SQL Queries
      3. 11.1.3. SQL Result Set Mapping
        1. 11.1.3.1. Mapping Foreign Keys
        2. 11.1.3.2. Multiple Result Mappings
        3. 11.1.3.3. Mapping Column Aliases
        4. 11.1.3.4. Mapping Scalar Result Columns
        5. 11.1.3.5. Mapping Compound Keys
        6. 11.1.3.6. Mapping Inheritance
      4. 11.1.4. Parameter Binding
    2. 11.2. Lifecycle Callbacks
      1. 11.2.1. Lifecycle Events
        1. 11.2.1.1. PrePersist and PostPersist
        2. 11.2.1.2. PreRemove and PostRemove
        3. 11.2.1.3. PreUpdate and PostUpdate
        4. 11.2.1.4. PostLoad
      2. 11.2.2. Callback Methods
        1. 11.2.2.1. Enterprise Contexts
      3. 11.2.3. Entity Listeners
        1. 11.2.3.1. Attaching Entity Listeners to Entities
        2. 11.2.3.2. Default Entity Listeners
      4. 11.2.4. Inheritance and Lifecycle Events
        1. 11.2.4.1. Inheriting Callback Methods
        2. 11.2.4.2. Inheriting Entity Listeners
        3. 11.2.4.3. Lifecycle Event Invocation Order
    3. 11.3. Validation
      1. 11.3.1. Using Constraints
      2. 11.3.2. Invoking Validation
      3. 11.3.3. Validation Groups
      4. 11.3.4. Creating New Constraints
        1. 11.3.4.1. Constraint Annotations
        2. 11.3.4.2. Constraint Implementation Classes
      5. 11.3.5. Validation in JPA
      6. 11.3.6. Enabling Validation
      7. 11.3.7. Setting Lifecycle Validation Groups
    4. 11.4. Concurrency
      1. 11.4.1. Entity Operations
      2. 11.4.2. Entity Access
    5. 11.5. Refreshing Entity State
    6. 11.6. Locking
      1. 11.6.1. Optimistic Locking
        1. 11.6.1.1. Versioning
        2. 11.6.1.2. Advanced Optimistic Locking Modes
          1. 11.6.1.2.1. Optimistic Read Locking
          2. 11.6.1.2.2. Optimistic Write Locking
        3. 11.6.1.3. Recovering from Optimistic Failures
      2. 11.6.2. Pessimistic Locking
        1. 11.6.2.1. Pessimistic Locking Modes
          1. 11.6.2.1.1. Pessimistic Write Locking
          2. 11.6.2.1.2. Pessimistic Read Locking
          3. 11.6.2.1.3. Pessimistic Forced Increment Locking
        2. 11.6.2.2. Pessimistic Scope
        3. 11.6.2.3. Pessimistic Timeouts
        4. 11.6.2.4. Recovering From Pessimistic Failures
    7. 11.7. Caching
      1. 11.7.1. Sorting Through the Layers
      2. 11.7.2. Shared Cache
        1. 11.7.2.1. Static Configuration of the Cache
        2. 11.7.2.2. Dynamic Cache Management
    8. 11.8. Utility Classes
      1. 11.8.1. PersistenceUtil
      2. 11.8.2. PersistenceUnitUtil
    9. 11.9. Summary
  18. 12. XML Mapping Files
    1. 12.1. The Metadata Puzzle
    2. 12.2. The Mapping File
      1. 12.2.1. Disabling Annotations
        1. 12.2.1.1. xml-mapping-metadata-complete
        2. 12.2.1.2. metadata-complete
      2. 12.2.2. Persistence Unit Defaults
        1. 12.2.2.1. schema
        2. 12.2.2.2. catalog
        3. 12.2.2.3. delimited-identifiers
        4. 12.2.2.4. access
        5. 12.2.2.5. cascade-persist
        6. 12.2.2.6. entity-listeners
      3. 12.2.3. Mapping File Defaults
        1. 12.2.3.1. package
        2. 12.2.3.2. schema
        3. 12.2.3.3. catalog
        4. 12.2.3.4. access
      4. 12.2.4. Queries and Generators
        1. 12.2.4.1. sequence-generator
        2. 12.2.4.2. table-generator
        3. 12.2.4.3. named-query
        4. 12.2.4.4. named-native-query
        5. 12.2.4.5. sql-result-set-mapping
      5. 12.2.5. Managed Classes and Mappings
        1. 12.2.5.1. Attributes
        2. 12.2.5.2. Tables
          1. 12.2.5.2.1. table
          2. 12.2.5.2.2. secondary-table
        3. 12.2.5.3. Identifier Mappings
          1. 12.2.5.3.1. id
          2. 12.2.5.3.2. embedded-id
          3. 12.2.5.3.3. id-class
        4. 12.2.5.4. Simple Mappings
          1. 12.2.5.4.1. basic
          2. 12.2.5.4.2. transient
          3. 12.2.5.4.3. version
        5. 12.2.5.5. Relationship and Collection Mappings
          1. 12.2.5.5.1. many-to-one
          2. 12.2.5.5.2. one-to-many
          3. 12.2.5.5.3. one-to-one
          4. 12.2.5.5.4. many-to-many
          5. 12.2.5.5.5. element-collection
        6. 12.2.5.6. Embedded Object Mappings
          1. 12.2.5.6.1. embedded
          2. 12.2.5.6.2. attribute-override
          3. 12.2.5.6.3. association-override
        7. 12.2.5.7. Inheritance Mappings
          1. 12.2.5.7.1. inheritance
          2. 12.2.5.7.2. discriminator-column
          3. 12.2.5.7.3. discriminator-value
          4. 12.2.5.7.4. attribute-override and association-override
        8. 12.2.5.8. Lifecycle Events
        9. 12.2.5.9. Entity Listeners
          1. 12.2.5.9.1. entity-listeners
          2. 12.2.5.9.2. exclude-default-listeners
          3. 12.2.5.9.3. exclude-superclass-listeners
    3. 12.3. Summary
  19. 13. Packaging and Deployment
    1. 13.1. Configuring Persistence Units
      1. 13.1.1. Persistence Unit Name
      2. 13.1.2. Transaction Type
      3. 13.1.3. Persistence Provider
      4. 13.1.4. Data Source
      5. 13.1.5. Mapping Files
      6. 13.1.6. Managed Classes
        1. 13.1.6.1. Local Classes
        2. 13.1.6.2. Classes in Mapping Files
        3. 13.1.6.3. Explicitly Listed Classes
        4. 13.1.6.4. Additional JARs of Managed Classes
      7. 13.1.7. Shared Cache Mode
      8. 13.1.8. Validation Mode
      9. 13.1.9. Adding Vendor Properties
    2. 13.2. Building and Deploying
      1. 13.2.1. Deployment Classpath
      2. 13.2.2. Packaging Options
        1. 13.2.2.1. EJB JAR
        2. 13.2.2.2. Web Archive
        3. 13.2.2.3. Persistence Archive
      3. 13.2.3. Persistence Unit Scope
    3. 13.3. Outside the Server
      1. 13.3.1. Configuring the Persistence Unit
        1. 13.3.1.1. Transaction Type
        2. 13.3.1.2. Data Source
        3. 13.3.1.3. Providers
        4. 13.3.1.4. Listing the Entities
      2. 13.3.2. Specifying Properties at Runtime
      3. 13.3.3. System Classpath
    4. 13.4. Schema Generation
      1. 13.4.1. Unique Constraints
      2. 13.4.2. Null Constraints
      3. 13.4.3. String-Based Columns
      4. 13.4.4. Floating Point Columns
      5. 13.4.5. Defining the Column
    5. 13.5. Summary
  20. 14. Testing
    1. 14.1. Testing Enterprise Applications
      1. 14.1.1. Terminology
      2. 14.1.2. Testing Outside the Server
      3. 14.1.3. Test Frameworks
    2. 14.2. Unit Testing
      1. 14.2.1. Testing Entities
      2. 14.2.2. Testing Entities in Components
      3. 14.2.3. The Entity Manager in Unit Tests
    3. 14.3. Integration Testing
      1. 14.3.1. Using the Entity Manager
        1. 14.3.1.1. Test Setup and Teardown
        2. 14.3.1.2. Switching Configurations for Testing
        3. 14.3.1.3. Minimizing Database Connections
      2. 14.3.2. Components and Persistence
        1. 14.3.2.1. Transaction Management
          1. 14.3.2.1.1. When to Use Transactions
          2. 14.3.2.1.2. Container-Managed Transactions
          3. 14.3.2.1.3. Bean-Managed Transactions
        2. 14.3.2.2. Container-Managed Entity Managers
        3. 14.3.2.3. Other Services
        4. 14.3.2.4. Using an Embedded EJB Container for Integration Testing
    4. 14.4. Best Practices
    5. 14.5. Summary
  21. 15. Migration
    1. 15.1. Migrating from CMP Entity Beans
      1. 15.1.1. Scoping the Challenge
      2. 15.1.2. Entity Bean Conversion
        1. 15.1.2.1. Converting the Business Interface
          1. 15.1.2.1.1. Migrating Properties
          2. 15.1.2.1.2. Migrating Business Methods
          3. 15.1.2.1.3. Migrating Container-Managed Relationships
        2. 15.1.2.2. Converting the Home Interface
          1. 15.1.2.2.1. Migrating Queries
          2. 15.1.2.2.2. Migrating Home Methods
          3. 15.1.2.2.3. Creating the Façade
    2. 15.2. Migrating from JDBC
    3. 15.3. Migrating from Other ORM Solutions
    4. 15.4. Leveraging Design Patterns
      1. 15.4.1. Transfer Object
        1. 15.4.1.1. Fine-Grained Transfer Objects
        2. 15.4.1.2. Coarse-Grained Transfer Objects
      2. 15.4.2. Session Façade
      3. 15.4.3. Data Access Object
      4. 15.4.4. Business Object
      5. 15.4.5. Fast Lane Reader
      6. 15.4.6. Active Record
    5. 15.5. Summary

Product information

  • Title: Pro JPA 2: Mastering the Java™ Persistence API
  • Author(s): Mike Keith, Merrick Schincariol
  • Release date: December 2009
  • Publisher(s): Apress
  • ISBN: 9781430219569