Jakarta Persistence 3.0 Specification Document
Total Page:16
File Type:pdf, Size:1020Kb
Jakarta Persistence Jakarta Persistence Team, https://projects.eclipse.org/projects/ee4j.jpa 3.0, September 08, 2020: Table of Contents Eclipse Foundation Specification License . 1 Disclaimers. 2 Scope . 3 1. Introduction . 4 1.1. Expert Group . 4 1.2. Document Conventions . 4 2. Entities. 6 2.1. The Entity Class . 6 2.2. Persistent Fields and Properties . 6 2.2.1. Example . 8 2.3. Access Type. 9 2.3.1. Default Access Type . 10 2.3.2. Explicit Access Type . 10 2.3.3. Access Type of an Embeddable Class . 11 2.3.4. Defaulted Access Types of Embeddable Classes and Mapped Superclasses . 11 2.4. Primary Keys and Entity Identity . 11 2.4.1. Primary Keys Corresponding to Derived Identities . 13 2.4.1.1. Specification of Derived Identities . 13 2.4.1.2. Mapping of Derived Identities . 14 2.4.1.3. Examples of Derived Identities . 14 2.5. Embeddable Classes . 25 2.6. Collections of Embeddable Classes and Basic Types . 26 2.7. Map Collections . 26 2.7.1. Map Keys . 27 2.7.2. Map Values . 27 2.8. Mapping Defaults for Non-Relationship Fields or Properties . 28 2.9. Entity Relationships . 28 2.10. Relationship Mapping Defaults . 30 2.10.1. Bidirectional OneToOne Relationships . 30 2.10.2. Bidirectional ManyToOne / OneToMany Relationships . 32 2.10.3. Unidirectional Single-Valued Relationships . 34 2.10.3.1. Unidirectional OneToOne Relationships . 34 2.10.3.2. Unidirectional ManyToOne Relationships . 35 2.10.4. Bidirectional ManyToMany Relationships . 36 2.10.5. Unidirectional Multi-Valued Relationships. 39 2.10.5.1. Unidirectional OneToMany Relationships . 39 2.10.5.2. Unidirectional ManyToMany Relationships . 40 2.11. Inheritance. 42 2.11.1. Abstract Entity Classes. 42 2.11.2. Mapped Superclasses . 43 2.11.3. Non-Entity Classes in the Entity Inheritance Hierarchy . 45 2.12. Inheritance Mapping Strategies . 46 2.12.1. Single Table per Class Hierarchy Strategy . 47 2.12.2. Joined Subclass Strategy . 47 2.12.3. Table per Concrete Class Strategy . 47 2.13. Naming of Database Objects . 48 3. Entity Operations . 52 3.1. EntityManager. 52 3.1.1. EntityManager Interface . 52 3.1.2. Example of Use of EntityManager API . 72 3.2. Entity Instance’s Life Cycle. 72 3.2.1. Entity Instance Creation . 73 3.2.2. Persisting an Entity Instance . 73 3.2.3. Removal. 74 3.2.4. Synchronization to the Database. 74 3.2.5. Refreshing an Entity Instance . 75 3.2.6. Evicting an Entity Instance from the Persistence Context . ..