Enterprise Java Development@TOPIC@

Java Persistence API: Relationship Exercise

Mapping Entity Relationships to the Database

Revision: v2013-08-19

2014-03-07 00:06 EST

Abstract

This document contains instructions for exercises to map Java class relations to the database using JPA. It covers the core and corner mapping concepts as well as demonstrates issues that can occur with JPA relationship mappings.


Purpose
1. JPA Entity Exercise Setup
1.1. Setup Maven Project
2. Mapping One-to-One Relationships
2.1. Setup
2.2. One-to-One Uni-directional Relationships
2.2.1. One-to-One Uni-directional Using a Foreign Key
2.2.2. One-to-One Uni-directional Using a Join Table
2.2.3. One-to-One Uni-directional Using a Primary Key Join
2.2.4. One-to-One Uni-directional Using MapsId
2.2.5. One-to-One Uni-directional Using Composite Primary/Foreign Keys
2.3. Mapping One-to-One Bi-directional Relationships
2.3.1. One-to-One Bi-directional Joined By Primary Key
2.3.2. One-to-One Bi-directional 0..1 Owner Relationship
2.3.3. One-to-One Bi-directional 0..1 Inverse Relationship
2.4. One-to-One EntityManager Automated Actions
2.4.1. One-to-One Using Cascades From Owner
2.4.2. One-to-One Using Cascades From Inverse
2.4.3. One-to-One Using Orphan Removal
2.5. Summary
3. Mapping One-to-Many Uni-directional Relationships
3.1. Setup
3.2. One-to-Many Uni-directional
3.2.1. One-to-Many Uni-directional with Join Table
3.2.2. One-to-Many Uni-directional using Foreign Key Join (from Child Table)
3.2.3. One-to-Many Uni-directional Mapping of Simple Types using ElementCollection
3.2.4. One-to-Many Uni-directional Mapping of Embeddable Type using ElementCollection
3.3. One-to-Many Provider Actions
3.3.1. One-to-Many Orphan Removal
3.4. Summary
4. JPA Collections
4.1. Setup
4.2. Entity Identity
4.2.1. Instance Id
4.2.2. Primary Key Id
4.2.3. Switching Ids
4.2.4. Business Id
4.3. Collection Ordering
4.3.1. Ordered Collections
4.4. Collection Interfaces
4.4.1. Using Maps with Collections
4.5. Summary
5. Mapping Many-to-One, Uni-directional Relationships
5.1. Setup
5.2. Many-to-One Uni-directional
5.2.1. Many-to-One Uni-directional Using a Foreign Key
5.2.2. Many-to-One Uni-directional Using a Compound Foreign Key
5.2.3. Many-to-One Uni-directional Using a MapsId
5.3. Summary
6. Mapping One-to-Many/Many-to-One Bi-directional Relationships
6.1. Setup
6.2. One-to-Many Bi-directional using Foreign Key Join
6.3. One-to-Many Bi-directional using Join Table
6.4. One-to-Many Bi-directional using Derived Composite Primary
6.5. Summary
7. Mapping Many-to-Many Relationships
7.1. Setup
7.2. Many-to-Many Uni-directional
7.3. Many-to-Many Bi-directional
7.4. Summary