<p><p><em>Pro JPA 2</em> introduces, explains, and demonstrates how to use the 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.</p><p>Authors <strong>Mike Keith</strong> and <s
Understanding JPA 2.2: Java Persistence API (agoncal fascicles)
β Scribed by Antonio Goncalves
- Tongue
- English
- Leaves
- 414
- Category
- Library
No coin nor oath required. For personal study only.
β¦ Synopsis
Applications are made up of business logic, interaction with other systems, user interfaces etc. and data. Most of the data that our applications manipulate have to be stored in datastores, retrieved, processed and analysed. If this datastore is a relational database and you use an object-oriented programming language such as Java, then you should have a look at JPA. JPA is an Object-Relational Mapping tool that maps Java objects to relational databases and allows query operations. In this fascicle, you will learn Java Persistence API, its annotations for mapping entities, as well as the Java Persistence Query Language and entity life cycle and a few advanced topics such as integrating JPA with other frameworks (Bean Validation, JTA, CDI, Spring).
β¦ Table of Contents
Foreword
About the Author
Acknowledgments
Introduction
Where Does This Fascicle Come From?
Who Is This Fascicle For?
How Is This Fascicle Structured?
Conventions
The Sample Application
Downloading and Running the Code
Getting Help
Contacting the Author
First Step with JPA
Understanding Java Persistence API
Understanding JDBC
Understanding Transactions
Understanding Object-Relational Mapping
Relational Databases
Entities
Mapping Entities
Managing Entities
JPA Overview
A Brief History of JPA
JCP and Eclipse Foundation
Java EE and Jakarta EE
Whatβs New in JPA 2.2?
Implementations
Getting Started
Developing Your First JPA Application
Setting up the Maven Dependencies
Mapping the Entity
Managing the Entity
Querying the Entity
Deployment Descriptor
Running the Tests
Checking the Database
Generating the Database Schema
A Closer Look at JPA
JPA Packages
Main JPA APIs
Anatomy of an Entity
Entity Life Cycle
Deployment Descriptors
Persistence Unit
Mapping Descriptor
Mapping Entities
Default Mapping
Elementary Mapping
Tables
@Table
@SecondaryTable
Primary Keys
@Id and @GeneratedValue
Composite Primary Keys
@EmbeddedId
@IdClass
Attributes
@Basic
@Column
Temporal
@Transient
@Enumerated
Collection of Basic Types
Map of Basic Types
Type Conversion
Mapping with XML
Embeddables
Collections of Embeddables
Relationship Mapping
Relationships in Objects
Relationships in Relational Databases
Entity Relationships
Unidirectional and Bidirectional
@OneToOne Unidirectional
@OneToMany Unidirectional
@ManyToMany Bidirectional
Fetching Relationships
Ordering Relationships
@OrderBy
@OrderColumn
Inheritance Mapping
Inheritance Strategies
Single-table-per-class Hierarchy Strategy
Joined-subclass Strategy
Table-per-concrete-class Strategy
Type of Classes in the Inheritance Hierarchy
Abstract Entity
Nonentity
Mapped Superclass
Managing Entities
Entity Management APIs
Entity Manager API
Obtaining an Entity Manager
Persistence Context
Manipulating Entities
Persisting an Entity
Finding by Id
Removing an Entity
Orphan Removal
Synchronising with the Database
Flushing an Entity
Refreshing an Entity
Content of the Persistence Context
Contains
Clear and Detach
Merging an Entity
Updating an Entity
Cascading Events
Querying Entities
Java Persistence Query Language
Select
From
Where
Binding Parameters
Subqueries
Order By
Group By and Having
Bulk Delete
Bulk Update
Queries
Query APIs
Query API
Query and TypedQuery
Dynamic Queries
Named Queries
Criteria API (or Object-oriented Queries)
Type-safe Criteria API
Native Queries
Stored Procedure Queries
Callbacks and Listeners
Entity Life Cycle
Callbacks
Listeners
Advanced Topics
Mapping Annotations on Fields and Properties
Access Type of an Embeddable Class
Overriding Attributes
Overriding Attributes in Inheritance
Overriding Attributes with Embeddables
Caching
Concurrency
Versioning
Optimistic Locking
Pessimistic Locking
Integrating JPA with Other Technologies
Bean Validation Integration
CDI Integration
JTA Integration
Spring Integration
Putting It All Together
Writing the Entities
Writing the Book Entity
Writing the Item Mapped Super-class
Writing the Chapter Embeddable
Writing the Author Entity
Database Structure
Writing the Persistence Units
Writing an SQL Script to Load Data
Writing the Main Class
Writing the BookTest Integration Tests
Compiling and Testing with Maven
Executing the Main Class with an H2 Server Database
Checking the Generated Schema
Summary
Setting up the Development Environment
Java 8
Architecture
A Brief History of Java
Installing the JDK
Checking for Java Installation
Maven 3.6.x
A Brief History of Maven
Project Descriptor
Managing Artifacts
Installing Maven
Checking for Maven Installation
Some Maven Commands
JUnit 5.x
A Brief History of JUnit
Writing Tests
Test Class
Fixtures
Test Methods
JUnit Assertions
Executing Tests
H2 Database
A Brief History of H2
Installing H2
Checking for H2 Installation
The H2 Console
Setting up the H2 JDBC Driver
Git
A Brief History of Git
Installing Git
Checking for Git Installation
Cloning Repository
Java Persistence API Specification Versions
JPA 2.2
JPA 2.1
JPA 2.0
JPA 1.0
References
Fascicles by the Same Author
Understanding Bean Validation 2.0
Understanding JPA 2.2
π SIMILAR VOLUMES
<p><em>Pro JPA 2</em> 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.</p> <p> Authors <strong>Mike Keith</stro
Maybe I am stubborn, or maybe just rational, but I see no reason to force EJBs on myself when there are many simpler and more robust ways of doing things. The entire book, except for one chapter on Java SE, assumes that you are wiring everything, including transactions with EJBs. I would suggest t
Maybe I am stubborn, or maybe just rational, but I see no reason to force EJBs on myself when there are many simpler and more robust ways of doing things. The entire book, except for one chapter on Java SE, assumes that you are wiring everything, including transactions with EJBs. I would suggest t
Maybe I am stubborn, or maybe just rational, but I see no reason to force EJBs on myself when there are many simpler and more robust ways of doing things. The entire book, except for one chapter on Java SE, assumes that you are wiring everything, including transactions with EJBs. I would suggest t