This Bugzilla instance is deprecated, and most Eclipse projects now use GitHub or Eclipse GitLab. Please see the deprecation plan for details.
Bug 307939 - Add support for ObjectReferenceMapping without a reference descriptor
Summary: Add support for ObjectReferenceMapping without a reference descriptor
Status: RESOLVED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Nobody - feel free to take it CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 296967
  Show dependency tree
 
Reported: 2010-04-01 16:45 EDT by Rick Barkhouse CLA
Modified: 2022-06-09 10:18 EDT (History)
2 users (show)

See Also:


Attachments
Core - Fix (3.73 KB, patch)
2010-04-05 14:21 EDT, Blaise Doughan CLA
no flags Details | Diff
MOXy - Fix (2.82 KB, patch)
2010-04-05 14:21 EDT, Blaise Doughan CLA
no flags Details | Diff
Core - Fix (12.49 KB, patch)
2010-04-07 14:23 EDT, Blaise Doughan CLA
no flags Details | Diff
Core - Fix (28.02 KB, patch)
2010-04-08 13:13 EDT, Blaise Doughan CLA
no flags Details | Diff
MOXy - Fix (5.30 KB, patch)
2010-04-08 13:15 EDT, Blaise Doughan CLA
no flags Details | Diff
Core - Fix (27.69 KB, patch)
2010-04-09 13:42 EDT, Blaise Doughan CLA
no flags Details | Diff
MOXy - Test Cases (27.28 KB, patch)
2010-04-12 16:00 EDT, Blaise Doughan CLA
no flags Details | Diff
Core - Fix (28.52 KB, patch)
2010-04-12 16:04 EDT, Blaise Doughan CLA
no flags Details | Diff
MOXy - Test Cases (43.17 KB, patch)
2010-04-12 16:57 EDT, Blaise Doughan CLA
no flags Details | Diff
Core - Fix (28.52 KB, patch)
2010-04-12 16:59 EDT, Blaise Doughan CLA
no flags Details | Diff
Core - Fix (33.46 KB, patch)
2010-04-13 11:27 EDT, Blaise Doughan CLA
no flags Details | Diff
MOXy - Test Cases (43.50 KB, patch)
2010-04-13 11:27 EDT, Blaise Doughan CLA
no flags Details | Diff
MOXy - Test Cases (78.84 KB, patch)
2010-04-14 16:08 EDT, Blaise Doughan CLA
no flags Details | Diff
Core - Fix (34.03 KB, patch)
2010-04-14 16:10 EDT, Blaise Doughan CLA
no flags Details | Diff
MOXy - Fix (5.30 KB, patch)
2010-04-14 16:11 EDT, Blaise Doughan CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Rick Barkhouse CLA 2010-04-01 16:45:28 EDT
Consider the following schema:

...
    <xs:complexType name="person">
        <xs:sequence>
            <xs:element name="company" type="xs:IDREF"/>
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="company">
        <xs:sequence>
            <xs:element name="name" type="xs:string"/>
        </xs:sequence>
        <xs:attribute name="id" type="xs:ID"/>
    </xs:complexType>
...

The JAXB RI will generate the following Java code:

public class Person {
    @XmlElement(required = true)
    @XmlIDREF
    @XmlSchemaType(name = "IDREF")
    protected Object company;
    ...
}

public class Company {
    @XmlAttribute(namespace = "myNamespace")
    @XmlJavaTypeAdapter(CollapsedStringAdapter.class)
    @XmlID
    @XmlSchemaType(name = "ID")
    protected String id;
    ...
}

Because there is no way to tell what Java type 'company' is, it is typed as Object on the Person class.  Since there is no TypeInfo created for Object, we will never generate an XMLObjectReferenceMapping in MappingsGenerator, but instead an XMLCompositeObjectMapping is created instead:

MappingsGenerator line 431:

TypeInfo reference = typeInfo.get(referenceClass.getQualifiedName());
if (reference != null) {
    if (property.isXmlIdRef()) {
        generateXMLObjectReferenceMapping(property, descriptor, namespaceInfo, referenceClass);
    } else {
        if (reference.isEnumerationType()) {
            generateDirectEnumerationMapping(property, descriptor, namespaceInfo, (EnumTypeInfo) reference);
        } else {
            generateCompositeObjectMapping(property, descriptor, namespaceInfo, referenceClass.getQualifiedName());
        }
    }

We will need to be able to support XMLObjectReferenceMappings that do not have a reference class set.
Comment 1 Blaise Doughan CLA 2010-04-05 14:21:11 EDT
Created attachment 163823 [details]
Core - Fix

This patch represents a work in progress.  If a reference descriptor is not set on the XMLObjectReferenceMapping then use the session to look up a descriptor.

Current Limitations:
- Only marshal operation is supported
- If a reference descriptor is not set, the target descriptor is assumed to have a single part key.
Comment 2 Blaise Doughan CLA 2010-04-05 14:21:50 EDT
Created attachment 163824 [details]
MOXy - Fix

This patch represents a work in progress.
Comment 3 Blaise Doughan CLA 2010-04-07 14:23:45 EDT
Created attachment 164108 [details]
Core - Fix
Comment 4 Blaise Doughan CLA 2010-04-08 13:13:34 EDT
Created attachment 164246 [details]
Core - Fix
Comment 5 Blaise Doughan CLA 2010-04-08 13:15:31 EDT
Created attachment 164247 [details]
MOXy - Fix
Comment 6 Blaise Doughan CLA 2010-04-09 13:42:40 EDT
Created attachment 164406 [details]
Core - Fix
Comment 7 Blaise Doughan CLA 2010-04-12 16:00:42 EDT
Created attachment 164623 [details]
MOXy - Test Cases
Comment 8 Blaise Doughan CLA 2010-04-12 16:04:05 EDT
Created attachment 164624 [details]
Core - Fix
Comment 9 Blaise Doughan CLA 2010-04-12 16:57:39 EDT
Created attachment 164629 [details]
MOXy - Test Cases
Comment 10 Blaise Doughan CLA 2010-04-12 16:59:12 EDT
Created attachment 164630 [details]
Core - Fix
Comment 11 Blaise Doughan CLA 2010-04-13 11:27:08 EDT
Created attachment 164733 [details]
Core - Fix
Comment 12 Blaise Doughan CLA 2010-04-13 11:27:47 EDT
Created attachment 164734 [details]
MOXy - Test Cases
Comment 13 Blaise Doughan CLA 2010-04-14 16:08:38 EDT
Created attachment 164891 [details]
MOXy - Test Cases
Comment 14 Blaise Doughan CLA 2010-04-14 16:10:47 EDT
Created attachment 164892 [details]
Core - Fix
Comment 15 Blaise Doughan CLA 2010-04-14 16:11:59 EDT
Created attachment 164893 [details]
MOXy - Fix
Comment 16 Blaise Doughan CLA 2010-04-15 10:32:01 EDT
Fix checked into trunk at rev:  6990

We now support null or Object as the reference class on XMLObjectReferenceMapping and XMLCollectionReferenceMapping (see below).  Note that when no reference class is set, the mapping is limited to one pk/fk pair.

     XMLCollectionReferenceMapping phoneNumbersMapping = new XMLCollectionReferenceMapping();
     phoneNumbersMapping.setAttributeName("phoneNumbers");
     phoneNumbersMapping.addSourceToTargetKeyFieldAssociation("phone-number-id/text()", null);
     phoneNumbersMapping.setReferenceClass(Object.class);
     phoneNumbersMapping.getContainerPolicy().setContainerClass(ArrayList.class);
     xmlDescriptor.addMapping(phoneNumbersMapping);

With this type of mapping when the reference is being resolved each cache with a primary key size of 1 will be checked.

Code Reviewed By:  Rick Barkhouse
Comment 17 Blaise Doughan CLA 2010-05-05 16:11:45 EDT
Fixed as above.
Comment 18 Eclipse Webmaster CLA 2022-06-09 10:18:46 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink