Skip to main content

Notice: This Wiki is now read only and edits are no longer possible. Please see: for the plan.

Jump to: navigation, search

EclipseLink/Development/JPA 2.0/nested embedding

Nested Embedding

JPA 2.0 Root | 207823 Enhancement Request


  • JSR-220 JPA 1.0 API Specification
    • See section 2.1.5 and 9.1.34 "Embeddable Classes"/"Embeddable Annotation"
  • JSR-317 JPA 2.0 API Specification - Oct 21 final draft
    • See section 2.3.3 Access Type of an Embeddable Class
    • See section 2.5, 2.6 and 9.1.12 "Embeddable Classes" of the [*See section 9.1.2 - 9.1.4 for Association Override and Attribute Override requirements.
    • See section 9.1.24 for "mappedBy" dot notation rules
    • See section 9.1.35 for "@OrderBy" dot notation rules


The following are new requirements introduced in the JPA 2.0 specification

  • R1: "An embeddable class may be used to represent the state of another embeddable class." - Sect 2.5
  • R2: "An embeddable class (including an embeddable class within another embeddable class) may contain a collection of a basic type or other embeddable class." - Sect 2.5
    • I interpret this to mean that embeddables can contain a collection of embeddables
  • R3: Direct or indirect circular containment dependencies among embeddable classes are not permitted. Sect 2.5 ref [15]
  • R4.0: An embeddable class may contain a relationship to an entity or collection of entities.
  • R4.1: Since instances of embeddable classes themselves have no persistent identity, the relationship from the referenced entity is to the entity which contains the embeddable instance(s) and not to the embeddable itself.[18]
  • R4.2: An embeddable class that is used as an embedded id or as a map key must not contain such a relationship.
  • R5: "The access type for and embedded object is determined by the access type of the entity in which itis embedded unless otherwise specified." Sect 2.3.3 and Sect 2.5 Open Issue #1

Issue Summary

The following issues directly affect this Nested Embeddables subset of the JPA 2.0 work.

  • I1: Access type for an embeddable is determined by the entity or the embeddable in which it is embedded - see 2.5 and 2.3.3 of the spec.

General Solution


  • In the JPA 2.0 specification, the following changes to the description of embeddable classes are made.
    • P.32 section 2.5 of the JPA 2.0 specification
      • Collections of embeddables are supported
      • Embeddables can be used as map keys and map values
  • JPA 1.0
    • @EmbeddedId (from JPA 1.0) annotation is used when the the composite primary key of an entity or mapped superclass is an embeddable


Test Model

There are two models that we will extend in the eclipselink.jpa.test suite.

  1. org.eclipse.persistence.testing.models.jpa.complexaggregate.HockeyTeam
  2. org.eclipse.persistence.testing.models.jpa.complexaggregate.World

The embeddable classes Vitals, TeamVitals and PersonalVitals are bound to their owning Entity (HockeyPlayer) and are not sharable in HockeyTeam or Role.

Nested embeddable uml class.gif

Requirements represented:

  • R1 - verify: entity state representation by composition (not aggregation)
    • (Vitals-->TeamVitals)
  • R4.0 - Embeddable has relationship to a collection of entities
    • (TeamVitals-->Role)
  • R4.0 - Embeddable has relationship to an entity
    • (TeamVitals-->HockeyTeam)

Requirements not represented yet:

This model will need to be extended to exercise the following requirements.

  • R2 - Embeddable contains a collection of basic types
  • R3 - A variant case to exclude circular references
  • R4.1 - we need another root parallel to HockeyPlayer that has it's own embeddables so that we can link TeamVitals to the containing entity of the other embeddable
  • R4.2 - we need an embedded Id that has a R4.1 link (variant) and one that does not


Work Required

  • For all tests verify that both JPA and ORM implementations adhere to the JPA 2.0 specification
  • Extend test model in eclipselink.jpa.test
  • Add model that includes an @EmbeddedId embedded composite primary key
  • Add processing of XML


Back to the top