Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
EclipseLink/Development/JPA 2.0/new collection mappings
Contents
Element Collections
Summary
JPA 2.0 introduces support for collections of Embeddables and primitives through the @ElementCollection annotation. Support for ElementCollection of primitives will be easily supported through our BasicCollection and BasicMap support and will only require annotation processing updates. Support for lists of Embeddables should be supportable through the AggregateCollectionMapping. Support for Maps of Embeddables will be more difficult and will require completion of the Map Collections support feature.
@OrderBy must also be supported on these collection types.
See section 2.1.5, 9.1.2, 9.1.4, 9.1.7, 9.1.11 and 9.1.35 for details.
Examples
@ElementCollection @Column(name="DESIGNATION") // CollectionTable will default in this case, Entity name + "_" + attribute name // JoinColumns will default in this case which are different from BasicCollection collection table default private Collection<String> designations;
@ElementCollection @MapKeyColumn(name="Q_DATE") @Column(name="QUOTE") @CollectionTable(name="EXPERT_QUOTES", joinColumns=@JoinColumn(name="EBC_ID")) public Map<Date, String> getQuotes() { return quotes; }
// An element collection representing an aggregate collection mapping. @ElementCollection // CollectionTable will default // Column is not applicable here. // JoinColumns will default. // Both expert and novice consumers will define attribute overrides and // association overrides to apply to their respective tables. private Collection<Record> records; ... @Embeddable public class Record {
Functional Requirements
Design
Core changes to accomodate JPA 2.0 requirements
In JPA 2.0 Embeddable may play two distinct roles: it could be either @Embedded or be a target of @ElementCollection. Moreover, the same embeddable class may play these two roles simultaneously in the same persistence unit several times: it may be embedded in one or more master classes and be a target of ElementCollection one or more times (with different CollectionTables).
The core equivalent of the first role is AggregateObjectMapping, which requires the target descriptor to have AggregateDescriptor type; the second is AggregateCollectionMapping which requires the target descriptor to have AggregateCollection type. AggregateObject descriptor is cloned by AggregateObjectMapping targeting it, therefore it could be used by several different aggregating descriptors. AggregateCollectionDescriptor is not cloned by AggregateCollectionMapping and therefore may be a target of only one AggregateCollectionMapping.
To accomodate JPA 2.0 requirements for Embeddable the following changes in the core were made:
- The target of AggregateCollectionMapping may be an AggregateDescriptor;
- Each AggregateCollectionMapping clones the target descriptor (just like AggregateObjectMapping does) and customizes it:
- if the original descriptor type was AggregateObjectDescriptor then clone descriptor type changed AggregateCollectionDescriptor;
- optionally maps to each field of the target table(s) a new field (that allows each AggregateCollectionMapping to use it's own target table(s)).
These changes allow to always map JPA 2.0 Embeddable to core AggregateObjectDescriptor.
Note that all original core functionality is still available.
Documentation
Testing
Work Required
- Develop model for testing
- approx 2 days
- Update Annotation Processing
- approx 2 days - processing @ElementCollection annotation / and XML for primitive
- approx 5 days - processing @ElementCollection annotation / and XML for Embeddables
- approx 5 days - integrating Map collections support for Embeddables
Open Issues
- How does the new JPA @CollectionTable relate to the existing EclipseLink @CollectionTable and what does it mean for users upgrading from one to the other.